Farhad Tasharofi

Hello guys,

I have a state machine workflow, and to create a timer, I used a delay inside an event driven.

Is there anyway to change timeoutduration of this delay to a new value, while the instance of the workflow is running, so the timer expires at that new time.

I couldn't find any code samples for that.

Any help would be greatly appreciated.



Re: Windows Workflow Foundation change delay timeoutduration

Matt Milner - Pluralsight

You can define a dependency property in your workflow for the timeout. Then bind the timeout on the delay to this property. When you want to change the value, simply change the property in your workflow.

Matt






Re: Windows Workflow Foundation change delay timeoutduration

Tom Lake

Another option would be to set the TimeoutDuration in the InitializeTimeoutDuration handler, like the following:

private void delayActivity1_InitializeTimeoutDuration(object sender, EventArgs e)

{

(sender as DelayActivity).TimeoutDuration = new TimeSpan(0, 5, 0);

}

Make sure you use the sender parameter or you will not have the correct instance of the delay. The reason is spawned contexts; for more info on that go here.






Re: Windows Workflow Foundation change delay timeoutduration

Richard Gavel

There is a piece of unstated information in your question that might impact the result....whether or not you are already within the delay activity at the time you want to change timeout duration. Once the activity begins, I believe you're not going to be able to change any of the properties of the activity.




Re: Windows Workflow Foundation change delay timeoutduration

Tasharofi

Hi guys,

Thank you for your replies, but as Richard mentioned, we are already within the delay activity at the time we want to make the change.

I think it's a common scenario where you want to discard a ticking timer and set a new one with a different timeout. Don't you think there should be a solution to this





Re: Windows Workflow Foundation change delay timeoutduration

Matt Milner - Pluralsight

In that case, you probably want to model this as an event in your state that allows the reset of the timer. Reset the timeout duration on the delay and then transition back to the same state. Now your delay is set for what you want, you have a way to change it, and you're good to go.

Matt






Re: Windows Workflow Foundation change delay timeoutduration

Farhad Tasharofi

Thanks for your reply.
Your solution works, but there are a whole bunch of other stuff in that state, like another timer or maybe later we want to add a sequential workflow inside this state, and making a transition back to the same state resets everything which is not desirable and a generic solution. Am I right




Re: Windows Workflow Foundation change delay timeoutduration

Matt Milner - Pluralsight

yes, the biggest issue would be if you had other delays as they would be reset. You would have to go through quite of bit of work to reset all of the timers.

Perhaps if you help us understand what it is you are trying to accomplish on a broader scale, someone will have a good solution for you. I'm guessing this might end up either with some changes to your model, or the use of some containing/super states to help out with this.

Matt






Re: Windows Workflow Foundation change delay timeoutduration

Farhad Tasharofi

Sure. Our workflow is a simple state machine, with three states. One of the states is "Active" state, and when the workflow goes into this state, two timers with different timeouts start ticking. After those delays, different types of notifications will be sent, and as I said we want to change those timeouts while they are still in the delay activity, so that the notification will be sent after this new time duration.



Re: Windows Workflow Foundation change delay timeoutduration

Iris Stern

Maybe, a StateInitializationActivity will solve the problem.

You can include it in your StateActivity and it will perform all work that has to be done before the state is waiting for events and timeouts.

Within the StateInitializationActivity you place a CodeActivity that sets

delayActivity1.TimeoutDuration = new Timespan(0 , 0, 10);

Hope that helps, Iris





Re: Windows Workflow Foundation change delay timeoutduration

Richard Gavel

Please read the thread more carefully, Iris. The problem is in resetting the duration during the execution of the delay activity itself. I am looking into a similar situation (though with only one delay). One problem I have with the existing delay activity is that it is a delay with a Timespan, not a delay until a certain DateTime, which is more apt towards resetting. I am looking into a new activity with its own service to handle the events, but when I use it, I will inside a Listen, listen for either a "Delay elapsed" from the delay or a "Delay change" event from the outside world. If I get a delay change event, I can change the delay activity definition and then return back to the same state and re-enter the Listen.




Re: Windows Workflow Foundation change delay timeoutduration

Tom Lake - MSFT

It is not possible to change the duration of a delay activity after it has already started executing.




Re: Windows Workflow Foundation change delay timeoutduration

Robert te Kaat - IS

It IS possible to change the duration during execution, however not with the out-of-the-box Delay-activity. My ConfigurableDelay-activity does exactly that. You can have it wake up every few days/week, independent of the configured duration. I used this functionality to fix a bug in the standard Delay-activity (http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1391954&SiteID=1), but you could modify the implementation.

Check my blog article on this topic (includes source code): http://blogs.infosupport.com/porint/archive/2007/09/04/Configurable-Delay-activity-for-WF.aspx