Search

Search:

Namespace:

Search Result
.
            • EventDrivenActivity
.

EventDrivenActivity

.

It is a CompositeActivity that is used to handle an event; typically it can be raised from the host or by the run time in reponse to a delay timer expiring. EventDrivenActivity is inherited from SequenceActivity; therefore it is a sequence that has the additional restriction that the first activity should be an IEventActivity.

.

The EventDrivenActivity is a CompositeActivity, meaning the EventDrivenActivity can contain other activities. The EventDrivenActivity is similar to the SequenceActivity activity, with some additional characteristics.

.

An EventDrivenActivity must have a parent that is either a ListenActivity, StateActivity, or StateMachineWorkflowActivity.

.

The first child of an EventDrivenActivity activity must be an activity that inherits from IEventActivity. All subsequent children can be activities of any type. The IEventActivity blocks and waits for the pending occurrence of some events, such as starting a timer or the arrival of a message. When the event occurs, the IEventActivity finishes running, and then all subsequent activities are executed.

.

When the StateMachineWorkflow contains an EventDrivenActvity, the EventDrivenActivity has some restrictions. The EventDrivenActivity may contain one, and only one, activity of type IEventActivity, and the HandleExternalEventActivity must be the first child activity. (An HandleExternalEventActivity cannot be in the event handler for a child activity and cannot be a child to the EventDrivenActivity if the HandleExternalEventActivity is not the first child.) As long as the first activity is the HandleExternalEventActivity, the event handler can contain any activities. If an activity other than HandleExternalEventActivity is contained in EventDrivenActivity, that activity cannot have an event handler.

.

For example, an activity that supports event handling can be used inside the EventDrivenActivity but the activity cannot have event handlers attached to itself.

.

Another example is that the EventDrivenActivity can contain a ConditionedActivityGroup, but the ConditionedActivityGroup itself cannot contain any HandleExternalEventActivity classes.

.
Summary
.

EventDrivenActivity

.

The ListenActivity is a CompositeActivity, meaning the ListenActivity can contain other activities. The ListenActivity can only contain EventDrivenActivity activities, and must have a minimum of two child activities.

.

SetStateActivity is always the last activity in the run path of a EventDrivenActivity activity.

.

One of the cool features of the SetStateActivity that may not be immediately obvious is the fact that it doesn't do the state switch immediately. Instead it saved the new target start in an internal property, named NextStateName on the StateMachineExecutionState type to be exact, and only does the state switch when the current EventDrivenActivity or StateInitializationActivity is finished. And just to be clear those are the only two activities where you can use a SetStateActivity.

.

So the cool part is that you don't need to have the SetStateActivity right at the bottom of the EventDrivenActivity but it can be anywhere in the execution flow. Something that might make the execution logic quite a bit easier.

.

The StateActivity represents a State in a StateMachineWorkflowActivity. State activities could contain one or more EventDrivenActivity, or StateActivity classes, one StateInitializationActivity class, and one StateFinalizationActivity class. SetState activities are used inside an EventHandlersActivity and StateInitializationActivity to move the state of the workflow.

.

When a StateActivity is executing, the only events that can be received are the events that can be handled by the EventDrivenActivity activities in the StateActivity and also the EventDrivenActivity activities attached to the enclosing StateActivity activities and the root Activity.

.

When the StateActivity starts running, the StateActivity will check to see whether a StateInitializationActivity activity is present or not. The StateActivity can have zero or one StateInitializationActivity activity. If a StateInitializationActivity activity is present the StateInitializationActivity will be executed. As soon as the StateInitializationActivity activity finishes, the StateActivity blocks events so that the StateActivity only receives events that can be handled by its EventDrivenActivity activities.

.

The StateMachineWorkflowActivity is a CompositeActivity, meaning the StateMachineWorkflowActivity can contain other activities. The StateMachineWorkflowActivity and the EventDrivenActivity activities are the only permitted child activities of the StateMachineWorkflowActivity. EventDrivenActivity activities are permitted because the root activity itself behaves like a state. Therefore, you can have EventDrivenActivity activities at the root level that are used by all the State activities in the StateMachineWorkflowActivity. EventDrivenActivity activities at this level provide a global mechanism for processing workflow events and automate state transitions. StateActivity activities provide a mechanism to define the various stages in the model.

.
    EventDrivenActivity leftBranch = new EventDrivenActivity();
.
    EventDrivenActivity rightBranch = new EventDrivenActivity();
.
    <EventDrivenActivity x:Name="eventDrivenActivity1">
.
    </EventDrivenActivity>
.
    <EventDrivenActivity x:Name="eventDrivenActivity2">
.
    </EventDrivenActivity>
.
  1. Add an EventDrivenActivity to the EventHandler.