語言

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 操作。

傳回

一個根活動 OutArgument 的字典, InOutArgument 並以參數名稱標示,代表工作流程的輸出。

範例

以下範例呼喚一個由活動 LongRunningDiceRoll 組成的工作流程。 活動 LongRunningDiceRoll 有兩個輸出自變數,代表骰子滾滾作業的結果。 這些資料可透過呼叫 EndInvoke取得。 當呼叫 回 EndInvoke 傳時,每個輸出參數會以參數名稱鍵化,返回在輸出字典中。

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 同步設計模式非同步呼叫的工作流程結果。 欲了解更多資訊,請參閱 非同步程式概述。

適用於