Tom Clarkson is a SharePoint consultant and entrepreneur based in Sydney, Australia.

Contact Details

Links



Recent Searches



Archives




Past Posts







RSS Feed

Changing TimeoutDuration with InitializeTimeoutDuration

SharePoint 2007, Workflow
Thursday May 22 2008

The workflow I have been working on includes some delay activities. It was difficult enough getting them to run at all using the ManualSchedulerService (I think UseActiveTimers fixed that issue), but now that I get into some more complete testing I notice that the timeouts (set in the InitializeTimeoutDuration event) aren't behaving as expected.

   

The event handlers were something like this:

   

        private void delayComputronUpdate_InitializeTimeoutDuration(object sender, EventArgs e)

        {

            if (DateTime.Now.TimeOfDay < Constants.ComputronUpdateTime)

            {

                delayComputronUpdate.TimeoutDuration = DateTime.Today + Constants.ComputronUpdateTime - DateTime.Now;

            }

            else

            {

                delayComputronUpdate.TimeoutDuration = DateTime.Today.AddDays(1) + Constants.ComputronUpdateTime - DateTime.Now;

            }

        }

   

There aren't any errors produced, but the timer event doesn't execute at the expected time. The problem turns out to be that even though the event is only ever set on delayComputronUpdate, sender is something else. ((DelayActivity)sender).TimeoutDuration is completely different to delayComputronUpdate.TimeoutDuration. If you don't use the sender, the delay activity will use the default timeout - easy enough to detect if it is zero, but the difference between two days and two business days isn't likely to be noticed during development.

   

The fixed code:

   

        private void delayComputronUpdate_InitializeTimeoutDuration(object sender, EventArgs e)

        {

            if (DateTime.Now.TimeOfDay < Constants.ComputronUpdateTime)

            {

                ((DelayActivity)sender).TimeoutDuration = DateTime.Today + Constants.ComputronUpdateTime - DateTime.Now;

            }

            else

            {

                ((DelayActivity)sender).TimeoutDuration = DateTime.Today.AddDays(1) + Constants.ComputronUpdateTime - DateTime.Now;

            }

        }

   

Comments

On 29 Oct 2008 12:25, Roger said:
Thanks for that!
On 04 Dec 2008 10:00, Evgeny Zyuzin said:
Thank you very much. I have same trouble TimeoutDuration was assgined but executed on default timeout value

Leave a comment