The Activity Execution Context

The activity execution model is encapsulated in a class called ActivityExecutionContext. An instance of this class is passed to each method that needs access to an activity execution context, most notably the Activity.Execute method. The following code shows the metadata for this class:

  namespace System.Workflow.ComponentModel {     public sealed class ActivityExecutionContext : IServiceProvider, IDisposable     {         public static readonly DependencyProperty CurrentExceptionProperty;         public Activity Activity { get; }         public Guid ContextGuid { get; }         public ActivityExecutionContextManager ExecutionContextManager { get; }         public void CancelActivity(Activity activity);         public void CloseActivity();         public void ExecuteActivity(Activity activity);         public T GetService<T>();         public object GetService(Type serviceType);         public void TrackData(object userData);         public void TrackData(string userDataKey, object userData);     } } 

The Activity property provides access to the activity instance in the current execution context. Remember that every time an activity executes, a new instance is created. Therefore, an activity instance on a workflow definition is not the same as the Activity property of the ActivityExecutionContext class. The following code illustrates this concept:

  if (MyWorkflow.Activities[0] == context.Activity) {     // this will never happen } 

The ActivityExecutionContext class also exposes a property that returns an instance of the Activity ExecutionContextManager class. Basically, this class enables you to create new execution contexts for an activity’s children. You do this by calling the CreateExecutionContext method, which takes an activity instance from the workflow definition. In addition, the ActivityExecutionContextManager class allows you to flag an already-created execution context as completed. Because execution contexts can be persisted when a persistence service is present, you can use the ActivityExecutionContextManager class to obtain access to persisted, as well as nonpersisted, contexts. To obtain a reference to a persisted execution context, you must have access to its ContextGuid. (This class is covered again shortly in a development example.)

The ActivityExecutionContext class also exposes methods that control an activity’s execution. CloseActivity causes the activity associated with the context to close. The CancelActivity and ExecuteActivity methods control child activities, which is why they take an Activity instance as a parameter.

Professional Windows Workflow Foundation
Professional Windows Workflow Foundation
ISBN: 0470053860
EAN: 2147483647
Year: 2004
Pages: 118
Authors: Todd Kitta

Similar book on Amazon
Pro WF: Windows Workflow in .NET 4 (Expert's Voice in .NET)
Pro WF: Windows Workflow in .NET 4 (Expert's Voice in .NET)
Pro WF: Windows Workflow in NET 3.5 (Expert's Voice in .NET)
Pro WF: Windows Workflow in NET 3.5 (Expert's Voice in .NET)
Microsoft  Windows  Workflow Foundation Step by Step (Microsoft Windows Step by Step)
Microsoft Windows Workflow Foundation Step by Step (Microsoft Windows Step by Step)
Essential Windows Workflow Foundation
Essential Windows Workflow Foundation © 2008-2017.
If you may any questions please contact us: