WorkflowInvoker.InvokeCompleted 事件

定義

在已完成或已取消其中一個 InvokeAsync 多載所叫用的工作流程時發生。

public:
 event EventHandler<System::Activities::InvokeCompletedEventArgs ^> ^ InvokeCompleted;
public event EventHandler<System.Activities.InvokeCompletedEventArgs> InvokeCompleted;
member this.InvokeCompleted : EventHandler<System.Activities.InvokeCompletedEventArgs> 
Public Custom Event InvokeCompleted As EventHandler(Of InvokeCompletedEventArgs) 
Public Event InvokeCompleted As EventHandler(Of InvokeCompletedEventArgs) 

事件類型

範例

下列範例會叫用由 LongRunningDiceRoll 活動組成的工作流程。 LongRunningDiceRoll 活動具有兩個輸出引數,這些引數代表擲骰作業的結果。 工作流程完成時,InvokeCompleted 處理常式就會擷取這些引數。

public sealed class LongRunningDiceRoll : Activity
{
    public OutArgument<int> D1 { get; set; }
    public OutArgument<int> D2 { get; set; }

    public LongRunningDiceRoll()
    {
        this.Implementation = () => new Sequence
        {
            Activities =
            {
                new WriteLine
                {
                    Text = "Rolling the dice for 5 seconds."
                },
                new Delay
                {
                    Duration = TimeSpan.FromSeconds(5)
                },
                new DiceRoll
                {
                    D1 = new OutArgument<int>(env => this.D1.Get(env)),
                    D2 = new OutArgument<int>(env => this.D2.Get(env))
                }
            }
        };
    }
}
AutoResetEvent syncEvent = new AutoResetEvent(false);

WorkflowInvoker invoker = new WorkflowInvoker(new LongRunningDiceRoll());

invoker.InvokeCompleted += delegate(object sender, InvokeCompletedEventArgs args)
{
    if (args.Cancelled == true)
    {
        Console.WriteLine("Workflow was cancelled.");
    }
    else if (args.Error != null)
    {
        Console.WriteLine("Exception: {0}\n{1}",
            args.Error.GetType().FullName,
            args.Error.Message);
    }
    else
    {
        Console.WriteLine("The two dice are {0} and {1}.",
            args.Outputs["D1"], args.Outputs["D2"]);
    }

    syncEvent.Set();
};

invoker.InvokeAsync("InvokeAsync Example");

Console.WriteLine("Waiting for the workflow to complete.");

// Wait for the workflow to complete.
syncEvent.WaitOne();

Console.WriteLine("The workflow is complete.");

備註

您可以處理這個事件,以便判斷使用其中一個 InvokeAsync 多載所叫用的工作流程是否已順利完成,並且擷取已完成工作流程的輸出引數。

適用於