Tom Clarkson

SharePoint, Startups and some other stuff

Changing TimeoutDuration with InitializeTimeoutDuration

with 2 comments

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;

            }

        }

   

Advertisement

Written by Tom Clarkson

May 22, 2008 at 3:43 pm

Posted in SharePoint, Workflow

2 Responses

Subscribe to comments with RSS.

  1. Thanks for that!

    Roger

    October 29, 2008 at 7:25 pm

  2. Thank you very much. I have same trouble TimeoutDuration was assgined but executed on default timeout value

    Evgeny Zyuzin

    December 5, 2008 at 5:00 am


Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

Please log in to WordPress.com to post a comment to your blog.

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.