Bewerken

Share via


WorkflowInvoker.InvokeAsync Method

Definition

Invokes a workflow asynchronously using the event-based asynchronous design pattern.

Overloads

InvokeAsync(TimeSpan, Object)

Invokes a workflow asynchronously with the specified time-out interval and a unique identifier.

InvokeAsync(IDictionary<String,Object>, TimeSpan)

Invokes a workflow asynchronously with the specified IDictionary<TKey,TValue> of input parameters and the specified time-out interval.

InvokeAsync(IDictionary<String,Object>, Object)

Invokes a workflow asynchronously using the specified IDictionary<TKey,TValue> of input parameters and a unique identifier.

InvokeAsync()

Invokes a workflow asynchronously.

InvokeAsync(Object)

Invokes a workflow asynchronously using the specified unique identifier.

InvokeAsync(IDictionary<String,Object>)

Invokes a workflow asynchronously using the specified IDictionary<TKey,TValue> of input parameters.

InvokeAsync(IDictionary<String,Object>, TimeSpan, Object)

Invokes a workflow asynchronously with the specified IDictionary<TKey,TValue> of input parameters, the specified time-out interval, and a unique identifier.

InvokeAsync(TimeSpan)

Invokes a workflow asynchronously with the specified time-out interval.

Remarks

To be notified when the workflow is complete, handle InvokeCompleted. To configure a time-out interval in which the workflow must complete, use one of the InvokeAsync overloads that take a TimeSpan.

This method invokes a workflow asynchronously using the event-based asynchronous design pattern. For more information, see Event-based Asynchronous Pattern Overview.

InvokeAsync(TimeSpan, Object)

Invokes a workflow asynchronously with the specified time-out interval and a unique identifier.

public:
 void InvokeAsync(TimeSpan timeout, System::Object ^ userState);
public void InvokeAsync (TimeSpan timeout, object userState);
member this.InvokeAsync : TimeSpan * obj -> unit
Public Sub InvokeAsync (timeout As TimeSpan, userState As Object)

Parameters

timeout
TimeSpan

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

userState
Object

A user-provided object used to distinguish this particular asynchronous invoke operation from other current asynchronous invoke operations.

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. When the workflow completes these are retrieved in the InvokeCompleted handler.

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))
                }
            }
        };
    }
}
AutoResetEvent syncEvent = new AutoResetEvent(false);

WorkflowInvoker invoker = new WorkflowInvoker(new LongRunningDiceRoll());

invoker.InvokeCompleted += delegate(object sender, InvokeCompletedEventArgs args)
{
    if (args.Cancelled == true)
    {
        Console.WriteLine("Workflow was cancelled.");
    }
    else if (args.Error != null)
    {
        Console.WriteLine("Exception: {0}\n{1}",
            args.Error.GetType().FullName,
            args.Error.Message);
    }
    else
    {
        Console.WriteLine("The two dice are {0} and {1}.",
            args.Outputs["D1"], args.Outputs["D2"]);
    }

    syncEvent.Set();
};

invoker.InvokeAsync("InvokeAsync Example");

Console.WriteLine("Waiting for the workflow to complete.");

// Wait for the workflow to complete.
syncEvent.WaitOne();

Console.WriteLine("The workflow is complete.");

Remarks

The userState parameter must be unique across all currently running InvokeAsync operations for the current activity. If userState is not unique, an ArgumentException is thrown. userState is used to identify the workflow in InvokeCompleted, and to cancel the workflow using CancelAsync.

To be notified when the workflow is complete, handle InvokeCompleted. If the workflow does not complete within the specified time-out interval the workflow is aborted and a TimeoutException is thrown.

Note

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 event-based asynchronous design pattern. For more information, see Event-based Asynchronous Pattern Overview.

Applies to

InvokeAsync(IDictionary<String,Object>, TimeSpan)

Invokes a workflow asynchronously with the specified IDictionary<TKey,TValue> of input parameters and the specified time-out interval.

public:
 void InvokeAsync(System::Collections::Generic::IDictionary<System::String ^, System::Object ^> ^ inputs, TimeSpan timeout);
public void InvokeAsync (System.Collections.Generic.IDictionary<string,object> inputs, TimeSpan timeout);
member this.InvokeAsync : System.Collections.Generic.IDictionary<string, obj> * TimeSpan -> unit
Public Sub InvokeAsync (inputs As IDictionary(Of String, Object), timeout As TimeSpan)

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.

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. When the workflow completes these are retrieved in the InvokeCompleted handler.

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))
                }
            }
        };
    }
}
AutoResetEvent syncEvent = new AutoResetEvent(false);

WorkflowInvoker invoker = new WorkflowInvoker(new LongRunningDiceRoll());

invoker.InvokeCompleted += delegate(object sender, InvokeCompletedEventArgs args)
{
    if (args.Cancelled == true)
    {
        Console.WriteLine("Workflow was cancelled.");
    }
    else if (args.Error != null)
    {
        Console.WriteLine("Exception: {0}\n{1}",
            args.Error.GetType().FullName,
            args.Error.Message);
    }
    else
    {
        Console.WriteLine("The two dice are {0} and {1}.",
            args.Outputs["D1"], args.Outputs["D2"]);
    }

    syncEvent.Set();
};

invoker.InvokeAsync("InvokeAsync Example");

Console.WriteLine("Waiting for the workflow to complete.");

// Wait for the workflow to complete.
syncEvent.WaitOne();

Console.WriteLine("The workflow is complete.");

Remarks

To be notified when the workflow is complete, handle InvokeCompleted. If the workflow does not complete within the specified time-out interval the workflow is aborted and a TimeoutException is thrown.

Note

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 event-based asynchronous design pattern. For more information, see Event-based Asynchronous Pattern Overview.

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by Invoke(IDictionary<String,Object>, TimeSpan).

Applies to

InvokeAsync(IDictionary<String,Object>, Object)

Invokes a workflow asynchronously using the specified IDictionary<TKey,TValue> of input parameters and a unique identifier.

public:
 void InvokeAsync(System::Collections::Generic::IDictionary<System::String ^, System::Object ^> ^ inputs, System::Object ^ userState);
public void InvokeAsync (System.Collections.Generic.IDictionary<string,object> inputs, object userState);
member this.InvokeAsync : System.Collections.Generic.IDictionary<string, obj> * obj -> unit
Public Sub InvokeAsync (inputs As IDictionary(Of String, Object), userState As Object)

Parameters

inputs
IDictionary<String,Object>

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

userState
Object

A user-provided object used to distinguish this particular asynchronous invoke operation from other current asynchronous invoke operations.

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. When the workflow completes these are retrieved in the InvokeCompleted handler.

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))
                }
            }
        };
    }
}
AutoResetEvent syncEvent = new AutoResetEvent(false);

WorkflowInvoker invoker = new WorkflowInvoker(new LongRunningDiceRoll());

invoker.InvokeCompleted += delegate(object sender, InvokeCompletedEventArgs args)
{
    if (args.Cancelled == true)
    {
        Console.WriteLine("Workflow was cancelled.");
    }
    else if (args.Error != null)
    {
        Console.WriteLine("Exception: {0}\n{1}",
            args.Error.GetType().FullName,
            args.Error.Message);
    }
    else
    {
        Console.WriteLine("The two dice are {0} and {1}.",
            args.Outputs["D1"], args.Outputs["D2"]);
    }

    syncEvent.Set();
};

invoker.InvokeAsync("InvokeAsync Example");

Console.WriteLine("Waiting for the workflow to complete.");

// Wait for the workflow to complete.
syncEvent.WaitOne();

Console.WriteLine("The workflow is complete.");

Remarks

The userState parameter must be unique across all currently running InvokeAsync operations for the current activity. If userState is not unique, an ArgumentException is thrown. userState is used to identify the workflow in InvokeCompleted, and to cancel the workflow using CancelAsync.

To be notified when the workflow is complete, handle InvokeCompleted. To configure a time-out interval in which the workflow must complete, use one of the InvokeAsync overloads that take a TimeSpan.

This method invokes a workflow asynchronously using the event-based asynchronous design pattern. For more information, see Event-based Asynchronous Pattern Overview.

Applies to

InvokeAsync()

Invokes a workflow asynchronously.

public:
 void InvokeAsync();
public void InvokeAsync ();
member this.InvokeAsync : unit -> unit
Public Sub InvokeAsync ()

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. When the workflow completes these are retrieved in the InvokeCompleted handler.

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))
                }
            }
        };
    }
}
AutoResetEvent syncEvent = new AutoResetEvent(false);

WorkflowInvoker invoker = new WorkflowInvoker(new LongRunningDiceRoll());

invoker.InvokeCompleted += delegate(object sender, InvokeCompletedEventArgs args)
{
    if (args.Cancelled == true)
    {
        Console.WriteLine("Workflow was cancelled.");
    }
    else if (args.Error != null)
    {
        Console.WriteLine("Exception: {0}\n{1}",
            args.Error.GetType().FullName,
            args.Error.Message);
    }
    else
    {
        Console.WriteLine("The two dice are {0} and {1}.",
            args.Outputs["D1"], args.Outputs["D2"]);
    }

    syncEvent.Set();
};

invoker.InvokeAsync("InvokeAsync Example");

Console.WriteLine("Waiting for the workflow to complete.");

// Wait for the workflow to complete.
syncEvent.WaitOne();

Console.WriteLine("The workflow is complete.");

Remarks

To be notified when the workflow is complete, handle InvokeCompleted. To configure a time-out interval in which the workflow must complete, use one of the InvokeAsync overloads that take a TimeSpan.

This method invokes a workflow asynchronously using the event-based asynchronous design pattern. For more information, see Event-based Asynchronous Pattern Overview.

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by Invoke().

Applies to

InvokeAsync(Object)

Invokes a workflow asynchronously using the specified unique identifier.

public:
 void InvokeAsync(System::Object ^ userState);
public void InvokeAsync (object userState);
member this.InvokeAsync : obj -> unit
Public Sub InvokeAsync (userState As Object)

Parameters

userState
Object

A user-provided object used to distinguish this particular asynchronous invoke operation from other current asynchronous invoke operations.

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. When the workflow completes these are retrieved in the InvokeCompleted handler.

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))
                }
            }
        };
    }
}
AutoResetEvent syncEvent = new AutoResetEvent(false);

WorkflowInvoker invoker = new WorkflowInvoker(new LongRunningDiceRoll());

invoker.InvokeCompleted += delegate(object sender, InvokeCompletedEventArgs args)
{
    if (args.Cancelled == true)
    {
        Console.WriteLine("Workflow was cancelled.");
    }
    else if (args.Error != null)
    {
        Console.WriteLine("Exception: {0}\n{1}",
            args.Error.GetType().FullName,
            args.Error.Message);
    }
    else
    {
        Console.WriteLine("The two dice are {0} and {1}.",
            args.Outputs["D1"], args.Outputs["D2"]);
    }

    syncEvent.Set();
};

invoker.InvokeAsync("InvokeAsync Example");

Console.WriteLine("Waiting for the workflow to complete.");

// Wait for the workflow to complete.
syncEvent.WaitOne();

Console.WriteLine("The workflow is complete.");

Remarks

The userState parameter must be unique across all currently running InvokeAsync operations for the current activity. If the userState parameter is not unique, an ArgumentException is thrown. userState is used to identify the workflow in InvokeCompleted, and to cancel the workflow using CancelAsync.

To be notified when the workflow is complete, handle InvokeCompleted. To configure a time-out interval in which the workflow must complete, use one of the InvokeAsync overloads that take a TimeSpan.

This method invokes a workflow asynchronously using the event-based asynchronous design pattern. For more information, see Event-based Asynchronous Pattern Overview.

Applies to

InvokeAsync(IDictionary<String,Object>)

Invokes a workflow asynchronously using the specified IDictionary<TKey,TValue> of input parameters.

public:
 void InvokeAsync(System::Collections::Generic::IDictionary<System::String ^, System::Object ^> ^ inputs);
public void InvokeAsync (System.Collections.Generic.IDictionary<string,object> inputs);
member this.InvokeAsync : System.Collections.Generic.IDictionary<string, obj> -> unit
Public Sub InvokeAsync (inputs As IDictionary(Of String, Object))

Parameters

inputs
IDictionary<String,Object>

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

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. When the workflow completes these are retrieved in the InvokeCompleted handler.

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))
                }
            }
        };
    }
}
AutoResetEvent syncEvent = new AutoResetEvent(false);

WorkflowInvoker invoker = new WorkflowInvoker(new LongRunningDiceRoll());

invoker.InvokeCompleted += delegate(object sender, InvokeCompletedEventArgs args)
{
    if (args.Cancelled == true)
    {
        Console.WriteLine("Workflow was cancelled.");
    }
    else if (args.Error != null)
    {
        Console.WriteLine("Exception: {0}\n{1}",
            args.Error.GetType().FullName,
            args.Error.Message);
    }
    else
    {
        Console.WriteLine("The two dice are {0} and {1}.",
            args.Outputs["D1"], args.Outputs["D2"]);
    }

    syncEvent.Set();
};

invoker.InvokeAsync("InvokeAsync Example");

Console.WriteLine("Waiting for the workflow to complete.");

// Wait for the workflow to complete.
syncEvent.WaitOne();

Console.WriteLine("The workflow is complete.");

Remarks

To be notified when the workflow is complete, handle InvokeCompleted. To configure a time-out interval in which the workflow must complete, use one of the InvokeAsync overloads that take a TimeSpan.

This method invokes a workflow asynchronously using the event-based asynchronous design pattern. For more information, see Event-based Asynchronous Pattern Overview.

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by Invoke(IDictionary<String,Object>).

Applies to

InvokeAsync(IDictionary<String,Object>, TimeSpan, Object)

Invokes a workflow asynchronously with the specified IDictionary<TKey,TValue> of input parameters, the specified time-out interval, and a unique identifier.

public:
 void InvokeAsync(System::Collections::Generic::IDictionary<System::String ^, System::Object ^> ^ inputs, TimeSpan timeout, System::Object ^ userState);
public void InvokeAsync (System.Collections.Generic.IDictionary<string,object> inputs, TimeSpan timeout, object userState);
member this.InvokeAsync : System.Collections.Generic.IDictionary<string, obj> * TimeSpan * obj -> unit
Public Sub InvokeAsync (inputs As IDictionary(Of String, Object), timeout As TimeSpan, userState As Object)

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.

userState
Object

A user-provided object used to distinguish this particular asynchronous invoke operation from other current asynchronous invoke operations.

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. When the workflow completes these are retrieved in the InvokeCompleted handler.

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))
                }
            }
        };
    }
}
AutoResetEvent syncEvent = new AutoResetEvent(false);

WorkflowInvoker invoker = new WorkflowInvoker(new LongRunningDiceRoll());

invoker.InvokeCompleted += delegate(object sender, InvokeCompletedEventArgs args)
{
    if (args.Cancelled == true)
    {
        Console.WriteLine("Workflow was cancelled.");
    }
    else if (args.Error != null)
    {
        Console.WriteLine("Exception: {0}\n{1}",
            args.Error.GetType().FullName,
            args.Error.Message);
    }
    else
    {
        Console.WriteLine("The two dice are {0} and {1}.",
            args.Outputs["D1"], args.Outputs["D2"]);
    }

    syncEvent.Set();
};

invoker.InvokeAsync("InvokeAsync Example");

Console.WriteLine("Waiting for the workflow to complete.");

// Wait for the workflow to complete.
syncEvent.WaitOne();

Console.WriteLine("The workflow is complete.");

Remarks

The userState parameter must be unique across all currently running InvokeAsync operations for the current activity. If userState is not unique, an ArgumentException is thrown. userState is used to identify the workflow in InvokeCompleted, and to cancel the workflow using CancelAsync.

To be notified when the workflow is complete, handle InvokeCompleted. If the workflow does not complete within the specified time-out interval the workflow is aborted and a TimeoutException is thrown.

Note

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 event-based asynchronous design pattern. For more information, see Event-based Asynchronous Pattern Overview.

Applies to

InvokeAsync(TimeSpan)

Invokes a workflow asynchronously with the specified time-out interval.

public:
 void InvokeAsync(TimeSpan timeout);
public void InvokeAsync (TimeSpan timeout);
member this.InvokeAsync : TimeSpan -> unit
Public Sub InvokeAsync (timeout As TimeSpan)

Parameters

timeout
TimeSpan

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

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. When the workflow completes these are retrieved in the InvokeCompleted handler.

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))
                }
            }
        };
    }
}
AutoResetEvent syncEvent = new AutoResetEvent(false);

WorkflowInvoker invoker = new WorkflowInvoker(new LongRunningDiceRoll());

invoker.InvokeCompleted += delegate(object sender, InvokeCompletedEventArgs args)
{
    if (args.Cancelled == true)
    {
        Console.WriteLine("Workflow was cancelled.");
    }
    else if (args.Error != null)
    {
        Console.WriteLine("Exception: {0}\n{1}",
            args.Error.GetType().FullName,
            args.Error.Message);
    }
    else
    {
        Console.WriteLine("The two dice are {0} and {1}.",
            args.Outputs["D1"], args.Outputs["D2"]);
    }

    syncEvent.Set();
};

invoker.InvokeAsync("InvokeAsync Example");

Console.WriteLine("Waiting for the workflow to complete.");

// Wait for the workflow to complete.
syncEvent.WaitOne();

Console.WriteLine("The workflow is complete.");

Remarks

To be notified when the workflow is complete, handle InvokeCompleted. If the workflow does not complete within the specified time-out interval the workflow is aborted and a TimeoutException is thrown.

Note

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 event-based asynchronous design pattern. For more information, see Event-based Asynchronous Pattern Overview.

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by Invoke(TimeSpan).

Applies to