This documentation is archived and is not being maintained.

WorkflowApplication Constructor (Activity)

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

Supported in: 4

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.