Export (0) Print
Expand All

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)

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.5.2, 4.5.1, 4.5, 4

.NET Framework Client Profile

Supported in: 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

© 2014 Microsoft