Search code examples
workflow-foundation-4workflow-foundation

Long running State Machine persistence with conditional transition


I'm developing a long running state machine in WF4 and I can't find a way to persist the state in presence of a conditional (triggerless) transition.

If on a state there are only transitions with a trigger (actually a NativeActivity with CanInduceIdle to true), arriving in that particular state i create the bookmarks, then the WF goes Idle and the InstanceStore take care to persist the state of the WF. Having a Triggerless Transition along with the others causes, while the condition is not satisfied, a rescheduling of all the transitions that prevent the WF to go Idle and be persisted. Here's an example:

Example1

When the WF starts (let's say with an object OBJ as InArgument) it goes to State1, here there are 3 transitions:

  1. a conditional transition that evaluates a property of the OBJ in the condition
  2. a transition with a trigger called Trigger tha receiving an object OBJ2 used to modify the OBJ handled in the WF
  3. a transition which gives the user the possibility to end the WF
If the condition evaluated in Conditional is true the WF goes to State2, where it can go Idle and be persisted after creating a bookmark. If the condition is false all the transition of State1 are rescheduled (Conditional too) and the WF can't be persisted.

The only solution I came up with, it's to put a previous state, with no actions in it to evaluate the condition, and reconnect the Trigger transition (that can modify the object I'm dealing with) to the BlankState to re-evaluate the condition of the triggerless transition.

Example2

Is there any way to evaluate a condition in a triggerless transition and let the WF go Idle if the condition is false? I also tried to put a shared loopback transition to intercept the false case (using !condition) and put a delay to idle and persist the WF but it seems that, in that case, no active bookmarks are saved.

Any ideas?


Solution

  • I doubt that there is a way to have a triggerless transition cause a persistable idle. You could create an activity that evaluates the condition and then causes the idle.