locked
State Machines & Event Driven Activities RRS feed

  • Question

  • I have noticed that IEventActivities in EventDrivenActivities do not have to transition to other states as part of thier behavior.. In  other words they stay active to execute time and time again.. Consider the following...

    <StateMachineWorkflowActivity InitialStateName="stateActivity1" x:Name="StateMachineWorkflowActivity" DynamicUpdateCondition="{x:Null}" CompletedStateName="stateActivity4" xmlns:ns0="clr-namespace:WorkManagement.Activities;Assembly=Activities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow">
        <EventDrivenActivity x:Name="eventDrivenActivity5">
            <ns0:Task x:Name="Task0" Instructions="Do This For All States..." />
            <ns0:WriteLine Text="Task 0 work..." x:Name="WriteLine1" />
            <ns0:WriteLine Text="More Task 0 work..." x:Name="WriteLine2" />
        </EventDrivenActivity>
        <StateActivity x:Name="stateActivity1">
            <StateInitializationActivity x:Name="stateInitializationActivity1">
                <ns0:WriteLine Text="In stateInitializationActivity1" x:Name="WriteLine3" />
            </StateInitializationActivity>
            <EventDrivenActivity x:Name="eventDrivenActivity1">
                <ns0:Task x:Name="Task1" Instructions="Do This..." />
                <ns0:WriteLine Text="Task 1 work..." x:Name="WriteLine4" />
                <ns0:WriteLine Text="More Task 1 work..." x:Name="WriteLine5" />
            </EventDrivenActivity>
            <EventDrivenActivity x:Name="eventDrivenActivity2">
                <ns0:Task x:Name="Task2" Instructions="Do That..." />
                <SetStateActivity x:Name="setStateActivity2" TargetStateName="stateActivity2" />
            </EventDrivenActivity>
            <StateFinalizationActivity x:Name="stateFinalizationActivity1">
                <ns0:WriteLine Text="In stateFinalizationActivity1" x:Name="WriteLine6" />
            </StateFinalizationActivity>
        </StateActivity>

    ,,,,,

    </StateMachineWorkflowActivity>

    Both <ns0:Task x:Name=Task0 /> and <ns0:Task x:Name=Task1 /> can execute multiple times without causing a <SetState...> to occur.. Is this as designed and is this type of usage recommended?

    Thanks
    Pete
    Friday, September 7, 2007 8:41 PM

Answers

  • Yes - it is a known pattern and sometimes is very useful.   You just have to make sure some other EventDriven can transition to the CompletedState.

     

    Friday, September 7, 2007 9:34 PM
  •  

    You are seeing expected behavior.  What you are running into the is the rule in Wf that an Activity instance can only run once.  What happens when the state done -  another copy of the activity is created by the parent (this is known as a persistable child ActivityExecutionContext).

     

    The only way to save shared state would be to have the property at the workflow level.

    Friday, September 7, 2007 9:50 PM

All replies

  • Yes - it is a known pattern and sometimes is very useful.   You just have to make sure some other EventDriven can transition to the CompletedState.

     

    Friday, September 7, 2007 9:34 PM
  • Ok, great. I have one more question about this pattern and its usage. From what I can tell if the IEventActivity (Task in my example) as a property, that property will be reset, and cannot hold state cumulative to all firings of the event. Is this true, or have I configured something incorrectly.

    To be clear, I added a dependency property to my Task event, that is a simple counter that counts how many times the event was fired. It is set to zero in the constructor, and is incremented for each firing of the event. However, when each event is fired its value is zero regardless of how many times the event was fired?

    I would expect it to be cumalative but I suspect it is a result of the IEvent Activity (Task) returning ActivityExecutionStatus.Closed when it recieves the event. Is this correct?

    Thanks
    Pete
    Friday, September 7, 2007 9:46 PM
  •  

    You are seeing expected behavior.  What you are running into the is the rule in Wf that an Activity instance can only run once.  What happens when the state done -  another copy of the activity is created by the parent (this is known as a persistable child ActivityExecutionContext).

     

    The only way to save shared state would be to have the property at the workflow level.

    Friday, September 7, 2007 9:50 PM