Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
WorkflowApplication Constructor (Activity)

WorkflowApplication Constructor (Activity)

.NET Framework 4.6 and 4.5

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


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

Supported in: 4.6, 4.5, 4

.NET Framework Client Profile

Supported in: 4
© 2015 Microsoft