Ανάγνωση στα Αγγλικά Επεξεργασία

Κοινή χρήση μέσω


WorkflowInvoker.BeginInvoke Method

Definition

Invokes a workflow asynchronously using the IAsyncResult asynchronous design pattern.

Overloads

BeginInvoke(AsyncCallback, Object)

Invokes a workflow asynchronously using the specified AsyncCallback and user-provided state.

BeginInvoke(IDictionary<String,Object>, AsyncCallback, Object)

Invokes a workflow asynchronously using the specified IDictionary<TKey,TValue> of input parameters, AsyncCallback, and user-provided state.

BeginInvoke(TimeSpan, AsyncCallback, Object)

Invokes a workflow asynchronously using the specified time-out interval, AsyncCallback, and user-provided state.

BeginInvoke(IDictionary<String,Object>, TimeSpan, AsyncCallback, Object)

Invokes a workflow asynchronously using the specified IDictionary<TKey,TValue> of input parameters, time-out interval, AsyncCallback, and user-provided state.

Remarks

For more information, see Asynchronous Programming Overview.

BeginInvoke(AsyncCallback, Object)

Invokes a workflow asynchronously using the specified AsyncCallback and user-provided state.

public IAsyncResult BeginInvoke (AsyncCallback callback, object state);

Parameters

callback
AsyncCallback

The method to be called when the workflow has completed.

state
Object

An optional application-specific object that contains information about the asynchronous operation.

Returns

A reference to the asynchronous invoke operation.

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. If EndInvoke 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 BeginInvoke overloads that take a TimeSpan.

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

Applies to

.NET Framework 4.8.1 και άλλες εκδόσεις
Προϊόν Εκδόσεις
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

BeginInvoke(IDictionary<String,Object>, AsyncCallback, Object)

Invokes a workflow asynchronously using the specified IDictionary<TKey,TValue> of input parameters, AsyncCallback, and user-provided state.

public IAsyncResult BeginInvoke (System.Collections.Generic.IDictionary<string,object> inputs, AsyncCallback callback, object state);

Parameters

inputs
IDictionary<String,Object>

The dictionary of input parameters to the workflow, keyed by argument name.

callback
AsyncCallback

The method to be called when the workflow has completed.

state
Object

An optional application-specific object that contains information about the asynchronous operation.

Returns

A reference to the asynchronous invoke operation.

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. If EndInvoke 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 BeginInvoke overloads that take a TimeSpan.

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

Applies to

.NET Framework 4.8.1 και άλλες εκδόσεις
Προϊόν Εκδόσεις
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

BeginInvoke(TimeSpan, AsyncCallback, Object)

Invokes a workflow asynchronously using the specified time-out interval, AsyncCallback, and user-provided state.

public IAsyncResult BeginInvoke (TimeSpan timeout, AsyncCallback callback, object state);

Parameters

timeout
TimeSpan

The interval in which the workflow must complete before it is aborted and a TimeoutException is thrown.

callback
AsyncCallback

The method to be called when the workflow has completed.

state
Object

An optional application-specific object that contains information about the asynchronous operation.

Returns

A reference to the asynchronous invoke operation.

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. If EndInvoke is called before the workflow completes, it blocks until the workflow completes. If the workflow does not complete within the specified time-out interval the workflow is aborted and a TimeoutException is thrown when the EndInvoke method is called.

Σημείωση

The TimeoutException is only thrown if the time-out interval elapses and the workflow becomes idle during execution. A workflow that takes longer than the specified time-out interval to complete completes successfully if the workflow does not become idle.

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

Applies to

.NET Framework 4.8.1 και άλλες εκδόσεις
Προϊόν Εκδόσεις
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

BeginInvoke(IDictionary<String,Object>, TimeSpan, AsyncCallback, Object)

Invokes a workflow asynchronously using the specified IDictionary<TKey,TValue> of input parameters, time-out interval, AsyncCallback, and user-provided state.

public IAsyncResult BeginInvoke (System.Collections.Generic.IDictionary<string,object> inputs, TimeSpan timeout, AsyncCallback callback, object state);

Parameters

inputs
IDictionary<String,Object>

The dictionary of input parameters to the workflow, keyed by argument name.

timeout
TimeSpan

The interval in which the workflow must complete before it is aborted and a TimeoutException is thrown.

callback
AsyncCallback

The method to be called when the workflow has completed.

state
Object

An optional application-specific object that contains information about the asynchronous operation.

Returns

A reference to the asynchronous invoke operation.

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. If EndInvoke is called before the workflow completes, it blocks until the workflow completes. If the workflow does not complete within the specified time-out interval the workflow is aborted and a TimeoutException is thrown when EndInvoke is called.

Σημείωση

The TimeoutException is only thrown if the time-out interval elapses and the workflow becomes idle during execution. A workflow that takes longer than the specified time-out interval to complete completes successfully if the workflow does not become idle.

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

Applies to

.NET Framework 4.8.1 και άλλες εκδόσεις
Προϊόν Εκδόσεις
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1