WorkflowApplication 构造函数

定义

创建 WorkflowApplication 类的新实例。Creates a new instance of the WorkflowApplication class.

重载

WorkflowApplication(Activity)

使用指定的工作流定义创建 WorkflowApplication 类的新实例。Creates a new instance of the WorkflowApplication class with the specified workflow definition.

WorkflowApplication(Activity, WorkflowIdentity)

使用指定的工作流定义和定义标识创建 WorkflowApplication 类的新实例。Creates a new instance of the WorkflowApplication class with the specified workflow definition and definition identity.

WorkflowApplication(Activity, IDictionary<String,Object>)

创建 WorkflowApplication 类的新实例,该实例使用指定的工作流定义和自变量值。Creates a new instance of the WorkflowApplication class that uses the specified workflow definition and argument values.

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

使用指定的工作流定义、参数值以及定义标识创建 WorkflowApplication 类的新实例。Creates a new instance of the WorkflowApplication class that uses the specified workflow definition and argument values, and definition identity.

WorkflowApplication(Activity)

使用指定的工作流定义创建 WorkflowApplication 类的新实例。Creates a new instance of the WorkflowApplication class with the specified workflow definition.

public:
 WorkflowApplication(System::Activities::Activity ^ workflowDefinition);
public WorkflowApplication (System.Activities.Activity workflowDefinition);
new System.Activities.WorkflowApplication : System.Activities.Activity -> System.Activities.WorkflowApplication
Public Sub New (workflowDefinition As Activity)

参数

workflowDefinition
Activity

工作流定义。The workflow definition.

示例

下面的示例使用 WorkflowApplication 承载一个工作流。The following example hosts a workflow using WorkflowApplication. WorkflowApplication实例是使用由单个活动组成的工作流定义构造的 DiceRollA WorkflowApplication instance is constructed using a workflow definition consisting of a single DiceRoll activity. DiceRoll 活动包含两个表示掷骰子操作结果的输出自变量。The DiceRoll activity has two output arguments that represent the results of the dice roll operation. 工作流完成时,将在 Completed 处理程序中检索输出,并向控制台显示以下输出。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}",
             e.TerminationException.GetType().FullName,
             e.TerminationException.Message);
     }
     else if (e.CompletionState == ActivityInstanceState.Canceled)
     {
         Console.WriteLine("Workflow {0} Canceled.", e.InstanceId);
     }
     else
     {
         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.
 wfApp.Run();

适用于

WorkflowApplication(Activity, WorkflowIdentity)

使用指定的工作流定义和定义标识创建 WorkflowApplication 类的新实例。Creates a new instance of the WorkflowApplication class with the specified workflow definition and definition identity.

public:
 WorkflowApplication(System::Activities::Activity ^ workflowDefinition, System::Activities::WorkflowIdentity ^ definitionIdentity);
public WorkflowApplication (System.Activities.Activity workflowDefinition, System.Activities.WorkflowIdentity definitionIdentity);
new System.Activities.WorkflowApplication : System.Activities.Activity * System.Activities.WorkflowIdentity -> System.Activities.WorkflowApplication
Public Sub New (workflowDefinition As Activity, definitionIdentity As WorkflowIdentity)

参数

workflowDefinition
Activity

工作流定义。The workflow definition.

definitionIdentity
WorkflowIdentity

定义标识。The definition identity.

适用于

WorkflowApplication(Activity, IDictionary<String,Object>)

创建 WorkflowApplication 类的新实例,该实例使用指定的工作流定义和自变量值。Creates a new instance of the WorkflowApplication class that uses the specified workflow definition and argument values.

public:
 WorkflowApplication(System::Activities::Activity ^ workflowDefinition, System::Collections::Generic::IDictionary<System::String ^, System::Object ^> ^ inputs);
public WorkflowApplication (System.Activities.Activity workflowDefinition, System.Collections.Generic.IDictionary<string,object> inputs);
new System.Activities.WorkflowApplication : System.Activities.Activity * System.Collections.Generic.IDictionary<string, obj> -> System.Activities.WorkflowApplication
Public Sub New (workflowDefinition As Activity, inputs As IDictionary(Of String, Object))

参数

workflowDefinition
Activity

工作流定义。The workflow definition.

inputs
IDictionary<String,Object>

在工作流定义的根活动上定义的自变量的值,由自变量名称键控。The values for arguments defined on the root activity of the workflow definition, keyed by argument name.

示例

下面的示例使用 WorkflowApplication 承载一个工作流。The following example hosts a workflow using WorkflowApplication. WorkflowApplication使用工作流定义构造实例,该工作流定义 Divide 包含采用两个输入参数的单个活动,以及一个包含两个要传递的值的输入参数字典(由参数名键控)。A WorkflowApplication instance is constructed 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. 将处理所需的工作流生命周期事件,并通过调用 Run 来调用工作流。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 Completed  
500 / 36 = 13 Remainder 32  
Workflow 8dc844c1-bbf8-4b21-a9a2-05f89e416055 Unloaded.  
public sealed class Divide : CodeActivity
{
    [RequiredArgument]
    public InArgument<int> Dividend { get; set; }

    [RequiredArgument]
    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}",
            e.TerminationException.GetType().FullName,
            e.TerminationException.Message);
    }
    else if (e.CompletionState == ActivityInstanceState.Canceled)
    {
        Console.WriteLine("Workflow {0} Canceled.", e.InstanceId);
    }
    else
    {
        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.
wfApp.Run();

适用于

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

使用指定的工作流定义、参数值以及定义标识创建 WorkflowApplication 类的新实例。Creates a new instance of the WorkflowApplication class that uses the specified workflow definition and argument values, and definition identity.

public:
 WorkflowApplication(System::Activities::Activity ^ workflowDefinition, System::Collections::Generic::IDictionary<System::String ^, System::Object ^> ^ inputs, System::Activities::WorkflowIdentity ^ definitionIdentity);
public WorkflowApplication (System.Activities.Activity workflowDefinition, System.Collections.Generic.IDictionary<string,object> inputs, System.Activities.WorkflowIdentity definitionIdentity);
new System.Activities.WorkflowApplication : System.Activities.Activity * System.Collections.Generic.IDictionary<string, obj> * System.Activities.WorkflowIdentity -> System.Activities.WorkflowApplication
Public Sub New (workflowDefinition As Activity, inputs As IDictionary(Of String, Object), definitionIdentity As WorkflowIdentity)

参数

workflowDefinition
Activity

工作流定义。The workflow definition.

inputs
IDictionary<String,Object>

定义标识。The definition identity.

definitionIdentity
WorkflowIdentity

在工作流定义的根活动上定义的自变量的值,由自变量名称键控。The values for arguments defined on the root activity of the workflow definition, keyed by argument name.

适用于