WorkflowApplication Constructor (Activity)

.NET Framework (current version)
 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Creates a new instance of the WorkflowApplication class with the specified workflow definition.

Namespace:   System.Activities
Assembly:  System.Activities (in System.Activities.dll)

public WorkflowApplication(
	Activity workflowDefinition
)

Parameters

workflowDefinition
Type: System.Activities.Activity

The workflow definition.

The following example hosts a workflow using WorkflowApplication. A WorkflowApplication instance is constructed using using a workflow definition consisting of a single DiceRoll activity. The DiceRoll activity has two output arguments that represent the results of the dice roll operation. When the workflow completes, the outputs are retrieved in the Completed handler, and the following output is displayed to the console.

Workflow aae3fb48-7229-4737-b969-d63e131b96b3 Completed. The two dice are 1 and 5. 
public sealed class DiceRoll : CodeActivity
{
    public OutArgument<int> D1 { get; set; }
    public OutArgument<int> D2 { get; set; }

    static Random r = new Random();

    protected override void Execute(CodeActivityContext context)
    {
        D1.Set(context, r.Next(1, 7));
        D2.Set(context, r.Next(1, 7));
    }
}
 // Create a WorkflowApplication instance.
 WorkflowApplication wfApp = new WorkflowApplication(new DiceRoll());

 // Subscribe to any desired workflow lifecycle events.
 wfApp.Completed = delegate(WorkflowApplicationCompletedEventArgs e)
 {
     if (e.CompletionState == ActivityInstanceState.Faulted)
     {
         Console.WriteLine("Workflow {0} Terminated.", e.InstanceId);
         Console.WriteLine("Exception: {0}\n{1}",
             e.TerminationException.GetType().FullName,
             e.TerminationException.Message);
     }
     else if (e.CompletionState == ActivityInstanceState.Canceled)
     {
         Console.WriteLine("Workflow {0} Canceled.", e.InstanceId);
     }
     else
     {
         Console.WriteLine("Workflow {0} Completed.", e.InstanceId);

         // Outputs can be retrieved from the Outputs dictionary,
         // keyed by argument name.
         Console.WriteLine("The two dice are {0} and {1}.",
             e.Outputs["D1"], e.Outputs["D2"]);
     }
 };

// Run the workflow.
 wfApp.Run();

.NET Framework
Available since 4.0
Return to top
Show: