Partager via


Using the EventDrivenActivity Activity

The EventDrivenActivity activity contains a sequence of activities whose execution is started by an event. This event is subscribed to by the first child activity in the sequence, which must derive from the IEventActivity interface. The IEventActivity interface is implemented by activities that wait for external events, such as HandleExternalEventActivity and DelayActivity.

In a sequential workflow, you can have multiple IEventActivity-derived activities inside an EventDrivenActivity activity.

In a state machine workflow, you can add an EventDrivenActivity activity as an immediate child of a StateActivity activity, or to the workflow itself. However, when you use an EventDrivenActivity activity in a state machine workflow, you can only use a single activity derived from IEventActivity, and this activity must be the first activity in the state. This is because the state machine workflow model that Windows Workflow Foundation implements processes only one EventDrivenActivity activity at a time. For example, if multiple IEventActivity activities inside an EventDrivenActivity activity were able to run, you would have a situation where an EventDrivenActivity activity becomes blocked while it waits for an IEventActivity that might never execute. This would prevent the state machine from being able to process any more messages.

For more information, see the EventDrivenActivity class and the IEventActivity interface of the System.Workflow.Activities namespace in the Windows Workflow Foundation Class Library reference.

For a code sample that demonstrates how to use the EventDrivenActivity activity, see the Listen Sample.

See Also

Reference

EventDrivenActivity
IEventActivity

Concepts

Using the ListenActivity Activity
Using the EventHandlersActivity Activity

Other Resources

Listen Sample
Windows Workflow Foundation Activities