SharePoint 2010 State Machine workflow delayActivity tip

Wed, Oct 3, 2012 One-minute read

If you’re using a delayActivity in your Visual Studio State Machine workflow, you are likely to want to use the InitializeTimeoutDuration handler to set the length of the delay.

An easy mistake to make is to think you could do the following:

private void DelayActivity_InitializeTimeoutDuration(object sender, EventArgs e)
        {
            delayActivity1.TimeoutDuration = new TimeSpan(0, 10, 0);
        }

However, this won’t work. This is because SharePoint will intialise a new instance of the delayActivity with the timeoutduration specified as default. To set the TimeoutDuration of your “actual” activity, you should do the following:

private void DelayActivity_InitializeTimeoutDuration(object sender, EventArgs e)
        {
            ((DelayActivity)sender).TimeoutDuration = new TimeSpan(0, 10, 0);
        }

Docs.