views:

142

answers:

1

I have a Windows Workflow Foundation (3.0) state machine in which I need certain states to change state based on the age of the state. For example, when the work flow enters state X the user needs to action it within 5 days. If this has not been done, the work flow needs to transition into state Y. So what I think I want is a state with an EventDriven Activity to handle the user's action, and a Sequence activity with a Delay activity that has a SetState activity which causes the state transition if the user hasn't actioned it in time.

States don't accept a Sequence activity directly, so I have tried to put this logic in the StateInitialization activity, but it doesn't allow Delays. I could put the delay in the previous state and another EventDriven activity and then transition to which ever state is appropriate but that doesn't really fit the business flow.

Is there a way this can be done in State Machines or should I be using a Sequential work flow?

A: 

You can achive this using state machine workflows easily.

You need to put a StateInitializationActivity and an EventDrivenActivity into your states. The EventDrivenActivity accepts a delay activity, put the logic after the timeout there, for example set another state. If the timer elapses earlier than the activities within the StateInitializationActivity, the state will be changed.

kay.herzam
Thanks Kay. I found this same solution here http://www.imason.com/blogs/jim_schwartz/archive/2008/12/15/repeating-a-state-machine-activity-indefinitely.aspx and it works (so I'm using it) but what is the event that is driving the EventDrivenActivity? In the rest of my app I fire off events from a web page. These events are then handled by the relevant Activity in the current state.
iamdudley
The event that triggers the EventDrivenActivity is the expired delay time.In an EventDrivenActivity you can put one activity which implements IEventActivity such as HandleExternalEventActivity, DelayActivity, or the WF 3.5 ReceiveActivity.
kay.herzam