WorkflowApplication 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
建立 WorkflowApplication 類別的新執行個體。
多載
WorkflowApplication(Activity) |
使用指定的工作流程定義,建立 WorkflowApplication 類別的新執行個體。 |
WorkflowApplication(Activity, WorkflowIdentity) |
使用指定的工作流程定義和定義識別,建立 WorkflowApplication 類別的新執行個體。 |
WorkflowApplication(Activity, IDictionary<String,Object>) |
建立使用指定工作流程定義及引數值的 WorkflowApplication 類別新執行個體。 |
WorkflowApplication(Activity, IDictionary<String,Object>, WorkflowIdentity) |
建立使用指定的工作流程定義和引數值以及定義識別的 WorkflowApplication 類別新執行個體。 |
WorkflowApplication(Activity)
使用指定的工作流程定義,建立 WorkflowApplication 類別的新執行個體。
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
工作流程定義。
範例
下列範例會使用 WorkflowApplication 來裝載工作流程。 系統會使用由單一 DiceRoll
活動組成的工作流程定義來建構 WorkflowApplication 執行個體。 DiceRoll
活動具有兩個輸出引數,這些引數代表擲骰作業的結果。 當工作流程完成時,Completed 處理常式就會擷取輸出,而且主控台會顯示下列輸出。
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 類別的新執行個體。
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
工作流程定義。
- definitionIdentity
- WorkflowIdentity
定義識別。
適用於
WorkflowApplication(Activity, IDictionary<String,Object>)
建立使用指定工作流程定義及引數值的 WorkflowApplication 類別新執行個體。
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
工作流程定義。
- inputs
- IDictionary<String,Object>
在工作流程定義的根活動上定義的引數值,以引數名稱做為索引鍵。
範例
下列範例會使用 WorkflowApplication 來裝載工作流程。 WorkflowApplication實例是使用工作流程定義來建構,其中包含接受兩個輸入自變數的單Divide
一活動,以及包含要傳遞之兩個值的輸入自變數字典,並以自變數名稱為索引鍵。 系統會處理所需的工作流程開發週期事件,並且透過呼叫 Run 叫用此工作流程。 當工作流程完成時,主控台就會顯示下列輸出。
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 類別新執行個體。
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
工作流程定義。
- inputs
- IDictionary<String,Object>
定義識別。
- definitionIdentity
- WorkflowIdentity
在工作流程定義的根活動上定義的引數值,以引數名稱做為索引鍵。