Basic Introduction to Activities in Windows Workflow Foundation


What are Activities

 

  • Building Blocks of Workflows
  • Are organized in a tree structure to compose workflows
  • Can be simple or composite (containing child activities)
  • Can be sequential (executed in the flow of the workflow) or event-driven (triggered by external events) 

Activity Execution Context (AEC)

 

AEC is the execution environment created for an activity when the Start method is called.

New AECs are created when child activities of an activity are run more than once, thus allowing the various instances to run independently. An activity can close only when it's execution contexts have been completed.

 

Activity States

 

Activities move through various stages in the life cycle of the workflow. Various stages of an activity are: Initialized, Executing, Canceling, Closed, Compensating and Faulting.

 

Windows Workflow Foundation Base Activity Library

 

Windows Workflow Foundation includes a set of out-of-the-box activities. These are available in the Visual Studio toolbox and ready to be configured to be used.

 

Following is a listing of some of the commonly used activities

 

  • Code Activity: Allows you to add Visual Basic.Net or Visual C# code to be executed in the workflow
  • Delay Activity: Allows you to add a delay period in the activity. 

Composite Activities

 

  • Sequence Activity: Specify a set of activities as an activity branch for sequential execution.
  • Parallel Activity: Specify two or more child activity branches for parallel execution 

Conditional Activites

 

  • IfElse Activity: Allows conditional execution of a branch based on the first "true" condition encountered.
  • IfElseActivityBranch: Represents a branch of activities executed depending on the results of the conditions specified in an IfElseActivity.
  • While Activity: Allows looping within a workflow until the specified condition evaluates to true.
  • ConditionedActivityGroup: Executes child activities based on a condition. 

Conditions can be expressed in one of the following ways

 

  • Using code as Code Conditions
  • Declaratively using Rules: The Rule Condition editor can be used for specifying conditions as Rules.
  • Specifying a Policy Activity containing a collection of conditions and corresponding actions.

Policy activities are a collection of simple rules and enable forward chaining. Forward chaining is the ability of the actions of one rule to cause other dependent rules to be re-evaluated.

 

State Workflow Activities

 

The following activities are used for creating State Machine workflows

 

  • State Activity: Represents a state in a state machine workflow.
  • StateInitialization Activity: Used to contain child activities executed when a State Activity is entered.
  • SetState Activity: Allows transitioning to a different state in the state machine workflow. 

Event Driven Activites

 

  • EventDriven Activity: Executed when a specified event occurs.
  • Listen Activity: Composite activity containing child EventDrivenActivity activities. 

Abnormal Operation /Error Handling Activities

 

  • Compensate Activity: Code to compensate for an error in an in-progress workflow.
  • FaultHandlers Activity, FaultHandler Activity: Used to handle exceptions of a specified type.
  • Terminate Activity: Allows termination of a workflow when an error condition occurs.
  • Throw Activity:  Captures business exceptions. 

Transaction

 

  • TransactionScope Activity: Specify Transaction and Exception handling 

External Operations

 

  • InvokeWebService Activity: Invoke a web service from the workflow
  • InvokeWorkflow Activity: Invoke another workflow from the workflow
  • CallExternalMethod Activity: Communications with a local service
  • WebServiceOutput Activity: Enables the workflow to respond to a web service request made to it. Used for exposing the workflow as a web service. 

Custom Activities

 

The workflow foundation provides a number of activities out of the box. In any case, as you get into real life development for workflows, you will want to create custom activities, specialized for your requirements. Custom activities can incorporate knowledge on domain specific areas, incorporating vertical business functionality or can be setup as specialized building blocks for the horizontal architecture.

 

Custom Activities are developed by deriving from the Activity base class or from an activity that derives from the Activity class.

 

The visual aspect in design as well as execution is the one that differentiates the workflow based applications from other frameworks. The ActivityDesigner and CompositeActivityDesigner base classes provide designer features and these classes or their derived classes can be used for custom activities.

 

A number of ready to use custom activity samples are available at : http://wf.netfx3.com/files/14/default.aspx

 

Performance Considerations

 

Note the following performance considerations when developing your custom activities and/or workflows

 

  • Activity Execution Cloning - Especially complex AEC cloning can have a performance impact.
  • Activities with Transaction Support
  • Activities with Compensation Support
  • Execution Tracking
  • Activity Complexity 

Enable Transaction Support, Compensation support and Execution tracking only in areas where required.

 

Resources

 

Conclusion

 

In this article, we took a look at the introductory concepts of Activities in Windows Workflows Foundation. The workflow foundation is full of Activity goodies and custom activity functionality should be the icing on the cake.

Disclaimer:

This article is for purely educational purposes and is a compilation of notes, material and my understanding on this subject. Any resemblance to other material is an un-intentional coincidence and should not be misconstrued as malicious, slanderous, or any anything else hereof.  

Up Next
    Ebook Download
    View all
    Learn
    View all