Muokkaa

Jaa


WorkflowInvoker.EndInvoke(IAsyncResult) Method

Definition

Returns the results of a workflow that was invoked using one of the BeginInvoke overloads.

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)

Parameters

result
IAsyncResult

The IAsyncResult that references the BeginInvoke operation that started the workflow.

Returns

A dictionary of the root activity's OutArgument and InOutArgument values keyed by argument name that represent the outputs of the workflow.

Examples

The following example invokes a workflow consisting of a LongRunningDiceRoll activity. The LongRunningDiceRoll activity has two output arguments that represent the results of the dice roll operation. These are retrieved by calling EndInvoke. When the call to EndInvoke returns, each output argument is returned in the outputs dictionary, keyed by argument name.

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.");
}

Remarks

To be notified when the workflow is complete and retrieve the output parameters of the workflow, call EndInvoke from the callback method specified by BeginInvoke. If EndInvoke is called before the workflow completes, it blocks until the workflow completes.

This method returns the result of a workflow invoked asynchronously using the IAsyncResult asynchronous design pattern. For more information, see Asynchronous Programming Overview.

Applies to