WorkflowApplication Constructor (Activity, IDictionary<String, Object>)

.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 that uses the specified workflow definition and argument values.

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

public WorkflowApplication(
	Activity workflowDefinition,
	IDictionary<string, object> inputs


Type: System.Activities.Activity

The workflow definition.

Type: System.Collections.Generic.IDictionary<String, Object>

The values for arguments defined on the root activity of the workflow definition, keyed by argument name.

The following example hosts a workflow using WorkflowApplication. A WorkflowApplication instance is constructed using using a workflow definition consisting of a single Divide activity that takes two input arguments, and a dictionary of input arguments containing the two values to be passed, keyed by argument name. The desired workflow lifecycle events are handled, and the workflow is invoked with a call to Run. When the workflow is completed, the following output is displayed to the console.

Workflow 8dc844c1-bbf8-4b21-a9a2-05f89e416055 Completed500 / 36 = 13 Remainder 32Workflow 8dc844c1-bbf8-4b21-a9a2-05f89e416055 Unloaded. 
public sealed class Divide : CodeActivity
    public InArgument<int> Dividend { get; set; }

    public InArgument<int> Divisor { get; set; }

    public OutArgument<int> Remainder { get; set; }
    public OutArgument<int> Result { get; set; }

    protected override void Execute(CodeActivityContext context)
        int quotient = Dividend.Get(context) / Divisor.Get(context);
        int remainder = Dividend.Get(context) % Divisor.Get(context);

        Result.Set(context, quotient);
        Remainder.Set(context, remainder);
int dividend = 500;
int divisor = 36;

Dictionary<string, object> inputs = new Dictionary<string, object>();
inputs.Add("Dividend", dividend);
inputs.Add("Divisor", divisor);

// Create a WorkflowApplication instance.
WorkflowApplication wfApp = new WorkflowApplication(new Divide(), inputs);

// 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("{0} / {1} = {2} Remainder {3}",
            dividend, divisor, e.Outputs["Result"], e.Outputs["Remainder"]);

// Run the workflow.

.NET Framework
Available since 4.0
Return to top