Share via


WorkflowInvoker.EndInvoke(IAsyncResult) 方法

定義

傳回使用其中一個 BeginInvoke 多載所叫用之工作流程的結果。

public:
 System::Collections::Generic::IDictionary<System::String ^, System::Object ^> ^ EndInvoke(IAsyncResult ^ result);
public System.Collections.Generic.IDictionary<string,object> EndInvoke (IAsyncResult result);
member this.EndInvoke : IAsyncResult -> System.Collections.Generic.IDictionary<string, obj>
Public Function EndInvoke (result As IAsyncResult) As IDictionary(Of String, Object)

參數

result
IAsyncResult

IAsyncResult,參考開始工作流程的 BeginInvoke 作業。

傳回

根活動之 OutArgumentInOutArgument 值 (以引數名稱作為索引鍵) 的字典,這些值代表工作流程的輸出。

範例

下列範例會叫用由 LongRunningDiceRoll 活動組成的工作流程。 LongRunningDiceRoll 活動具有兩個輸出引數,這些引數代表擲骰作業的結果。 您可以透過呼叫 EndInvoke,擷取這些引數。 當 EndInvoke 的呼叫傳回時,每個輸出引數都會傳入 outputs 字典 (以引數名稱做為索引鍵)。

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))
                }
            }
        };
    }
}
static void BeginInvokeExample()
{
    WorkflowInvoker invoker = new WorkflowInvoker(new LongRunningDiceRoll());

    string userState = "BeginInvoke example";
    IAsyncResult result = invoker.BeginInvoke(new AsyncCallback(WorkflowCompletedCallback), userState);

    // You can inspect result from the host to determine if the workflow
    // is complete.
    Console.WriteLine("result.IsCompleted: {0}", result.IsCompleted);

    // The results of the workflow are retrieved by calling EndInvoke, which
    // can be called from the callback or from the host. If called from the
    // host, it blocks until the workflow completes. If a callback is not
    // required, pass null for the callback parameter.
    Console.WriteLine("Waiting for the workflow to complete.");
    IDictionary<string, object> outputs = invoker.EndInvoke(result);

    Console.WriteLine("The two dice are {0} and {1}.",
        outputs["D1"], outputs["D2"]);
}

static void WorkflowCompletedCallback(IAsyncResult result)
{
    Console.WriteLine("Workflow complete.");
}

備註

若要在工作流程完成並擷取工作流程的輸出參數時收到通知,請從 EndInvoke 指定的 callback 方法呼叫BeginInvoke。 如果在工作流程完成前呼叫 EndInvoke,它會封鎖直到工作流程完成為止。

這個方法會傳回使用 IAsyncResult 非同步設計模式,以非同步方式叫用之工作流程的結果。 如需詳細資訊,請參閱 異步程序設計概觀

適用於