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 的调用返回时,将在输出字典中返回由自变量名键控的每个输出自变量。

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 异步设计模式以异步方式调用的工作流的结果。 有关详细信息,请参阅 异步编程概述

适用于