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 工作流的结果。 有关详细信息,请参阅 异步编程概述

适用于