Metodo WorkflowInvoker.BeginInvoke (IDictionary<String, Object>, AsyncCallback, Object)

.NET Framework (current version)
 

Data di pubblicazione: ottobre 2016

Richiama un flusso di lavoro in modo asincrono usando il IDictionary<TKey, TValue> specificato dei parametri di input, AsyncCallback e dello stato fornito dall'utente.

Spazio dei nomi:   System.Activities
Assembly:  System.Activities (in System.Activities.dll)

public IAsyncResult BeginInvoke(
	IDictionary<string, object> inputs,
	AsyncCallback callback,
	object state
)

Parametri

inputs
Type: System.Collections.Generic.IDictionary<String, Object>

Il dizionario di parametri di input al flusso di lavoro codificati dal nome dell'argomento.

callback
Type: System.AsyncCallback

Metodo da chiamare quando il flusso di lavoro è completato.

state
Type: System.Object

Oggetto facoltativo specifico dell'applicazione che contiene informazioni sull'operazione asincrona.

Valore restituito

Type: System.IAsyncResult

Un riferimento all'operazione asincrona invoke.

To be notified when the workflow is complete and retrieve the output parameters of the workflow, call M:System.Activities.WorkflowInvoker.EndInvoke(System.IAsyncResult) from the callback method. If M:System.Activities.WorkflowInvoker.EndInvoke(System.IAsyncResult) is called before the workflow completes, it blocks until the workflow completes. To configure a time-out interval in which the workflow must complete, use one of the Overload:System.Activities.WorkflowInvoker.BeginInvoke overloads that take a T:System.TimeSpan.

This method invokes a workflow asynchronously using the T:System.IAsyncResult asynchronous design pattern. crdefaultAsynchronous Programming Overviewhttp://go.microsoft.com/fwlink/?LinkId=141764.

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 M:System.Activities.WorkflowInvoker.EndInvoke(System.IAsyncResult). When the call to M:System.Activities.WorkflowInvoker.EndInvoke(System.IAsyncResult) 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.");
}

.NET Framework
Disponibile da 4.0
Torna all'inizio
Mostra: