WorkflowApplication Constructor (Activity^)

.NET Framework (current version)

The .NET API Reference documentation has a new home. Visit the .NET API Browser on 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)

	Activity^ 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}",
     else if (e.CompletionState == ActivityInstanceState.Canceled)
         Console.WriteLine("Workflow {0} Canceled.", e.InstanceId);
         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.

.NET Framework
Available since 4.0
Return to top