Working with Workflow Activities (From Microsoft Elearning)
Activities
1.Conditional
Conditional activities enable you to make tests and control the execution of your workflow according to the results. WF includes the following activities:
- IfElseActivity. You use the IfElseActivity to conditionally execute one of several alternative IfElseBranchActivity branches. You place a condition on each IfElseBranchActivity. If the condition evaluates to true, the runtime executes the activities that in the IfElseBranchActivity, otherwise, the next IfElseBranchActivity condition is evaluated, and so on. You do not have to put a condition on the last IfElseBranchActivity because it is treated as the else branch.
- WhileActivity. The WhileActivity continuously executes any activities contained within it, as long as its condition evaluates to true. The condition is reevaluated at the completion of each loop.
- ConditionedActivityGroup. The ConditionedActivityGroup continuously executes any activities within it until its condition evaluates to true. Each individual activity within the ConditionedActivityGroup has a When condition. Each activity executes only when the When condition evaluates to true.
- ReplicatorActivity. The ReplicatorActivity completes its execution when its UntilCondition property evaluates to true. 
 
2.Transaction
WF enables you to define transactions within your workflows to ensure data integrity. If a failure occurs when a transaction is executing, all the activities that have executed within that transaction roll back their changes. The transaction succeeds or fails as one unit.
To create a transaction within your workflow, use the TransactionScopeActivity. You can create any number of other activities within the TransactionScopeActivity. The workflow runtime enrolls all these activities in the transaction. If a failure occurs within the TransactionScopeActivity, the transaction is aborted.
3.Code
The code activity enables you to include custom procedural code in your workflow without creating a complete custom activity. Use the code activity if you have a simple task that other built-in activities cannot perform.
In Visual Studio 2005, in Workflow Designer, you can create a code activity by dragging it onto the workflow from the toolbox. You must specify the method to execute in the ExecuteCode property of the code activity. When you do this, Visual Studio 2005 creates the method for you in the code-behind file and displays it in a code window. Visual Studio creates the following code if you set the ExecuteCode property to “Example”.
[Visual Basic]
Private Sub Example(ByVal sender As Object, _
    ByVal e As EventArgs)
End Sub
[Visual C#]
private void Example(object sender, EventArgs e)
{
}
 
                     
                    
                 
                    
                 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号