WorkflowInvoker.BeginInvoke 方法

定义

使用 IAsyncResult 异步设计模式以异步方式调用工作流。Invokes a workflow asynchronously using the IAsyncResult asynchronous design pattern.

重载

BeginInvoke(AsyncCallback, Object)

使用指定的 AsyncCallback 和用户提供的状态以异步方式调用工作流。Invokes a workflow asynchronously using the specified AsyncCallback and user-provided state.

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

使用指定的输入参数的 IDictionary<TKey,TValue>AsyncCallback 和用户提供的状态以异步方式调用工作流。Invokes a workflow asynchronously using the specified IDictionary<TKey,TValue> of input parameters, AsyncCallback, and user-provided state.

BeginInvoke(TimeSpan, AsyncCallback, Object)

使用指定的超时间隔、AsyncCallback 和用户提供的状态以异步方式调用工作流。Invokes a workflow asynchronously using the specified time-out interval, AsyncCallback, and user-provided state.

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

使用指定的输入参数的 IDictionary<TKey,TValue>、超时间隔、AsyncCallback 和用户提供的状态以异步方式调用工作流。Invokes a workflow asynchronously using the specified IDictionary<TKey,TValue> of input parameters, time-out interval, AsyncCallback, and user-provided state.

注解

有关详细信息,请参阅 异步编程概述For more information, see Asynchronous Programming Overview.

BeginInvoke(AsyncCallback, Object)

使用指定的 AsyncCallback 和用户提供的状态以异步方式调用工作流。Invokes a workflow asynchronously using the specified AsyncCallback and user-provided state.

public:
 IAsyncResult ^ BeginInvoke(AsyncCallback ^ callback, System::Object ^ state);
public IAsyncResult BeginInvoke (AsyncCallback callback, object state);
member this.BeginInvoke : AsyncCallback * obj -> IAsyncResult
Public Function BeginInvoke (callback As AsyncCallback, state As Object) As IAsyncResult

参数

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.

返回

IAsyncResult

对异步调用操作的引用。A reference to the asynchronous invoke operation.

示例

下面的示例调用包含单个 LongRunningDiceRoll 活动的工作流。The following example invokes a workflow consisting of a LongRunningDiceRoll activity. LongRunningDiceRoll 活动包含两个表示掷骰子操作结果的输出自变量。The LongRunningDiceRoll activity has two output arguments that represent the results of the dice roll operation. 通过调用 EndInvoke 可检索这些参数。These are retrieved by calling EndInvoke. 当对 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.");
}

注解

若要在工作流完成时得到通知并检索该工作流的输出参数,请调用 EndInvoke 方法的 callbackTo be notified when the workflow is complete and retrieve the output parameters of the workflow, call EndInvoke from the callback method. 如果在工作流完成之前调用 EndInvoke,此调用将会受到阻止,直至工作流完成。If EndInvoke is called before the workflow completes, it blocks until the workflow completes. 若要配置工作流必须在其间完成的超时间隔,请使用一种采用 BeginInvokeTimeSpan 重载。To configure a time-out interval in which the workflow must complete, use one of the BeginInvoke overloads that take a TimeSpan.

此方法使用 IAsyncResult 异步设计模式以异步方式调用工作流。This method invokes a workflow asynchronously using the IAsyncResult asynchronous design pattern. 有关详细信息,请参阅 异步编程概述For more information, see Asynchronous Programming Overview.

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

使用指定的输入参数的 IDictionary<TKey,TValue>AsyncCallback 和用户提供的状态以异步方式调用工作流。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<System::String ^, System::Object ^> ^ inputs, AsyncCallback ^ callback, System::Object ^ state);
public IAsyncResult BeginInvoke (System.Collections.Generic.IDictionary<string,object> inputs, AsyncCallback callback, object state);
member this.BeginInvoke : System.Collections.Generic.IDictionary<string, obj> * AsyncCallback * obj -> IAsyncResult
Public Function BeginInvoke (inputs As IDictionary(Of String, Object), callback As AsyncCallback, state As Object) As IAsyncResult

参数

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.

返回

IAsyncResult

对异步调用操作的引用。A reference to the asynchronous invoke operation.

示例

下面的示例调用包含单个 LongRunningDiceRoll 活动的工作流。The following example invokes a workflow consisting of a LongRunningDiceRoll activity. LongRunningDiceRoll 活动包含两个表示掷骰子操作结果的输出自变量。The LongRunningDiceRoll activity has two output arguments that represent the results of the dice roll operation. 通过调用 EndInvoke 可检索这些参数。These are retrieved by calling EndInvoke. 当对 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.");
}

注解

若要在工作流完成时得到通知并检索该工作流的输出参数,请调用 EndInvoke 方法的 callbackTo be notified when the workflow is complete and retrieve the output parameters of the workflow, call EndInvoke from the callback method. 如果在工作流完成之前调用 EndInvoke,此调用将会受到阻止,直至工作流完成。If EndInvoke is called before the workflow completes, it blocks until the workflow completes. 若要配置工作流必须在其间完成的超时间隔,请使用一种采用 BeginInvokeTimeSpan 重载。To configure a time-out interval in which the workflow must complete, use one of the BeginInvoke overloads that take a TimeSpan.

此方法使用 IAsyncResult 异步设计模式以异步方式调用工作流。This method invokes a workflow asynchronously using the IAsyncResult asynchronous design pattern. 有关详细信息,请参阅 异步编程概述For more information, see Asynchronous Programming Overview.

BeginInvoke(TimeSpan, AsyncCallback, Object)

使用指定的超时间隔、AsyncCallback 和用户提供的状态以异步方式调用工作流。Invokes a workflow asynchronously using the specified time-out interval, AsyncCallback, and user-provided state.

public:
 IAsyncResult ^ BeginInvoke(TimeSpan timeout, AsyncCallback ^ callback, System::Object ^ state);
public IAsyncResult BeginInvoke (TimeSpan timeout, AsyncCallback callback, object state);
member this.BeginInvoke : TimeSpan * AsyncCallback * obj -> IAsyncResult
Public Function BeginInvoke (timeout As TimeSpan, callback As AsyncCallback, state As Object) As IAsyncResult

参数

timeout
TimeSpan

工作流必须在被中止和引发 TimeoutException 之前在其中完成的时间间隔。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.

返回

IAsyncResult

对异步调用操作的引用。A reference to the asynchronous invoke operation.

示例

下面的示例调用包含单个 LongRunningDiceRoll 活动的工作流。The following example invokes a workflow consisting of a LongRunningDiceRoll activity. LongRunningDiceRoll 活动包含两个表示掷骰子操作结果的输出自变量。The LongRunningDiceRoll activity has two output arguments that represent the results of the dice roll operation. 通过调用 EndInvoke 可检索这些参数。These are retrieved by calling EndInvoke. 当对 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.");
}

注解

若要在工作流完成时得到通知并检索该工作流的输出参数,请调用 EndInvoke 方法的 callbackTo be notified when the workflow is complete and retrieve the output parameters of the workflow, call EndInvoke from the callback method. 如果在工作流完成之前调用 EndInvoke,此调用将会受到阻止,直至工作流完成。If EndInvoke is called before the workflow completes, it blocks until the workflow completes. 如果工作流未在指定的超时间隔内完成,那么工作流就会被中止,并且在调用 TimeoutException 方法时会引发 EndInvokeIf 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.

备注

仅在达到超时间隔且工作流在执行期间进入空闲状态时才会引发 TimeoutExceptionThe 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.

此方法使用 IAsyncResult 异步设计模式以异步方式调用工作流。This method invokes a workflow asynchronously using the IAsyncResult asynchronous design pattern. 有关详细信息,请参阅 异步编程概述For more information, see Asynchronous Programming Overview.

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

使用指定的输入参数的 IDictionary<TKey,TValue>、超时间隔、AsyncCallback 和用户提供的状态以异步方式调用工作流。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<System::String ^, System::Object ^> ^ inputs, TimeSpan timeout, AsyncCallback ^ callback, System::Object ^ state);
public IAsyncResult BeginInvoke (System.Collections.Generic.IDictionary<string,object> inputs, TimeSpan timeout, AsyncCallback callback, object state);
member this.BeginInvoke : System.Collections.Generic.IDictionary<string, obj> * TimeSpan * AsyncCallback * obj -> IAsyncResult
Public Function BeginInvoke (inputs As IDictionary(Of String, Object), timeout As TimeSpan, callback As AsyncCallback, state As Object) As IAsyncResult

参数

inputs
IDictionary<String,Object>

由自变量名称键控的工作流输入参数字典。The dictionary of input parameters to the workflow, keyed by argument name.

timeout
TimeSpan

工作流必须在被中止和引发 TimeoutException 之前在其中完成的时间间隔。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.

返回

IAsyncResult

对异步调用操作的引用。A reference to the asynchronous invoke operation.

示例

下面的示例调用包含单个 LongRunningDiceRoll 活动的工作流。The following example invokes a workflow consisting of a LongRunningDiceRoll activity. LongRunningDiceRoll 活动包含两个表示掷骰子操作结果的输出自变量。The LongRunningDiceRoll activity has two output arguments that represent the results of the dice roll operation. 通过调用 EndInvoke 可检索这些参数。These are retrieved by calling EndInvoke. 当对 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.");
}

注解

若要在工作流完成时得到通知并检索该工作流的输出参数,请调用 EndInvoke 方法的 callbackTo be notified when the workflow is complete and retrieve the output parameters of the workflow, call EndInvoke from the callback method. 如果在工作流完成之前调用 EndInvoke,此调用将会受到阻止,直至工作流完成。If EndInvoke is called before the workflow completes, it blocks until the workflow completes. 如果工作流未在指定的超时间隔内完成,那么工作流就会被中止,并且在调用 TimeoutException 时会引发 EndInvokeIf the workflow does not complete within the specified time-out interval the workflow is aborted and a TimeoutException is thrown when EndInvoke is called.

备注

仅在达到超时间隔且工作流在执行期间进入空闲状态时才会引发 TimeoutExceptionThe 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.

此方法使用 IAsyncResult 异步设计模式以异步方式调用工作流。This method invokes a workflow asynchronously using the IAsyncResult asynchronous design pattern. 有关详细信息,请参阅 异步编程概述For more information, see Asynchronous Programming Overview.

适用于