Jensan_Ahsay

Hi,

I am writting a sequential workflow with a while activity, which would check if the value in the database has changed periodically. It is something like:

...

while (!hasChanged){

System.Threading.Thread.Sleep(30 * 1000);

LogToActivityHistory (...)

}

...

I didn't use the delayActivity because i know that there is a big bug with that, and we will never know when the hotfix will be released.

For the first 5 minutes it works perfectly, although the logs are missing. However after that, it stops working, and the old logs appear. Then I wait for an hour but nothing happens again, even if I change the value of the database.

I can understand why the logs are missing when it works, and it is not important to me. But I really want to know why it stops after 5 minutes. Even the query timeout of the SQL server is 600 seconds, not 5 minutes. I have also tried to create a new connection everytime when there is any DB operation, but it also fails. Connection.Close(), Connection.Dispose(), "Connection = null" are added all around the codes but the result is exactly the same.

Please help. Thank you very much.

Jensan



Re: SharePoint - Workflow Sequential Workflow - While Activity - Stop checking after 5 minutes

DaveM.

Hmmm...does seem a bit odd.

OK, first thought: you're running into an issue with your workflow dehydrating (persisting). My understanding of the dehydration process was that this would not be the problem, but it's the first thing that comes to mind. The question then is, how to test it and / or fix it

A few thoughts:

1. Are there other workflows or other instances of this workflow running

2. Calling thread.sleep may pose a problem. Try replacing that with a System.Timer object

3. Does it stop exactly at 5 minutes or just somewhere around there

I don't think any of this will solve the problem , but hopefully something will move us in the right direction. Let me know how it goes.

-Dave





Re: SharePoint - Workflow Sequential Workflow - While Activity - Stop checking after 5 minutes

Jensan_Ahsay

Thank you for your reply.

1. No, only one item is working on the workflow.

3. I can't tell if it is exactly 5 minutes. However, I have tried to change the time from 30 seconds to 10 seconds, and they've got the same results. For 30 seconds, a log is inserted every 30 seconds, and for 10 seconds it works similarly. By checking the logging time, it stopped at 5 minutes after the first log was inserted. I have also tested for a few times, and all the results are: the log stopped after 5 minutes.

One thing I want to mention here is, when I edit the workflow item again, it comes alive again...

But there is no event waiting activity added inside the loop...weird...

I have tried method #2, and it works now, thank you.

I put a onWorkflowItemChanged acitivity in the loop, and use a timer to fire that event, like this:

while (!hasChanged){

Timer myTimer = new Timer(30*1000);

myTimer.Enabled = true;
myTimer.AutoReset = true;
myTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);

OnWorkflowItemChanged(....);

logToHistory(...);

}

private void OnTimedEvent(object source, ElapsedEventArgs e)
{
this.WorkflowProperties.Item.Update();
}

The logs are also working perfectly this time.

Thanks again





Re: SharePoint - Workflow Sequential Workflow - While Activity - Stop checking after 5 minutes

DaveM.

Hmmm...interestng. Using the onWorkflowItemChanged forces a deyhdrate/rehydrate cycle so that could still have been part of the problem. I think getting the Thread.Sleep call out of the picture helped also.

Glad it's working...

Dave





Re: SharePoint - Workflow Sequential Workflow - While Activity - Stop checking after 5 minutes

Jensan_Ahsay

It is found that doing "iisreset" would stop the timer!

The backup job will also do some kind of this, and stop the timer....

I have scheduled to backup every mid-night, and that's the cause the workflow stop at mid-night everyday.

I don't know what else I can do.....

Please help.

Thank you.





Re: SharePoint - Workflow Sequential Workflow - While Activity - Stop checking after 5 minutes

Fred Morrison

I use a DelayFor activity for waiting a specified TimeSpan amount of time.

One thing you need to be aware of the setting of job-workflow.

The setting of that PropertyName for your SP server will effectively "round up" your DelayFor TimeSpan to the "next nearest multiple" of whatever job-workflow is set too.

Burned me big time until I learned how to:

1. Get it's current value

2. Change the value.

Be default the MINIMUM wait interval is 5 minutes (maybe 10, it's been a while since I had a brand new virtual machine), so you can DelayFor 3 minutes all you want - it's going to wait a minimum of 5 (maybe 10 if you're really unlucky).

From a CMD window:

CD C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN\

stsadm -o getproperty -pn job-workflow -url http://localhost

Write the value down.

If you want to change the minimum to something shorter:

stsadm -o setproperty -pn job-workflow -propertyvalue "every 2 minutes between 0 and 59" -url http://localhost

I've never seen adequate documentation on how a companion value, job-immediate-alerts is affected by or possibly affects job-workflow, so if necessary, check (and change if necessary) the following value too:

stsadm -o getproperty -pn job-immediate-alerts -url http://localhost

stsadm -o setproperty -pn job-immediate-alerts -url http://localhost -pv "every 2 minutes between 0

and 59"

Some day, Microsoft will put these into a nice web page in SP Central Admin where you can actually CHANGE them, not just admire their current values, which is all I've ever been able to do :-)