WorkflowInvoker.BeginInvoke 方法

定义

使用 IAsyncResult 异步设计模式异步调用工作流。

重载

名称 说明
BeginInvoke(AsyncCallback, Object)

使用指定的 AsyncCallback 和用户提供的状态异步调用工作流。

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

使用指定的 IDictionary<TKey,TValue> 输入参数 AsyncCallback和用户提供的状态异步调用工作流。

BeginInvoke(TimeSpan, AsyncCallback, Object)

使用指定的超时间隔 AsyncCallback和用户提供的状态异步调用工作流。

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

使用指定的 IDictionary<TKey,TValue> 输入参数、超时间隔 AsyncCallback和用户提供的状态异步调用工作流。

注解

有关详细信息,请参阅 异步编程概述

BeginInvoke(AsyncCallback, Object)

使用指定的 AsyncCallback 和用户提供的状态异步调用工作流。

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

工作流完成后要调用的方法。

state
Object

一个可选的特定于应用程序的对象,其中包含有关异步作的信息。

返回

对异步调用操作的引用。

示例

以下示例调用由活动组成的 LongRunningDiceRoll 工作流。 活动 LongRunningDiceRoll 具有两个输出参数,这些参数表示掷骰子操作的结果。 通过调用 EndInvoke来检索这些内容。 调用 EndInvoke 返回时,输出字典中会返回每个输出参数,按参数名称进行键键。

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该方法调用callback。 如果在 EndInvoke 工作流完成之前调用,则会阻止工作流完成。 若要配置工作流必须完成的超时间隔,请使用采用的重载之 BeginInvokeTimeSpan

此方法使用 IAsyncResult 异步设计模式异步调用工作流。 有关详细信息,请参阅 异步编程概述

适用于

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

使用指定的 IDictionary<TKey,TValue> 输入参数 AsyncCallback和用户提供的状态异步调用工作流。

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>

工作流的输入参数字典,按参数名称进行键控。

callback
AsyncCallback

工作流完成后要调用的方法。

state
Object

一个可选的特定于应用程序的对象,其中包含有关异步作的信息。

返回

对异步调用操作的引用。

示例

以下示例调用由活动组成的 LongRunningDiceRoll 工作流。 活动 LongRunningDiceRoll 具有两个输出参数,这些参数表示掷骰子操作的结果。 通过调用 EndInvoke来检索这些内容。 调用 EndInvoke 返回时,输出字典中会返回每个输出参数,按参数名称进行键键。

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该方法调用callback。 如果在 EndInvoke 工作流完成之前调用,则会阻止工作流完成。 若要配置工作流必须完成的超时间隔,请使用采用的重载之 BeginInvokeTimeSpan

此方法使用 IAsyncResult 异步设计模式异步调用工作流。 有关详细信息,请参阅 异步编程概述

适用于

BeginInvoke(TimeSpan, AsyncCallback, Object)

使用指定的超时间隔 AsyncCallback和用户提供的状态异步调用工作流。

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 引发工作流之前必须完成的间隔。

callback
AsyncCallback

工作流完成后要调用的方法。

state
Object

一个可选的特定于应用程序的对象,其中包含有关异步作的信息。

返回

对异步调用操作的引用。

示例

以下示例调用由活动组成的 LongRunningDiceRoll 工作流。 活动 LongRunningDiceRoll 具有两个输出参数,这些参数表示掷骰子操作的结果。 通过调用 EndInvoke来检索这些内容。 调用 EndInvoke 返回时,输出字典中会返回每个输出参数,按参数名称进行键键。

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该方法调用callback。 如果在 EndInvoke 工作流完成之前调用,则会阻止工作流完成。 如果工作流未在指定的超时间隔内完成,则工作流中止,并在调用该方法时TimeoutException引发一个EndInvoke工作流。

注释

仅在达到超时间隔且工作流在执行期间进入空闲状态时才会引发 TimeoutException。 如果工作流未进入空闲状态,那么完成时间超过指定超时间隔的工作流将会成功完成。

此方法使用 IAsyncResult 异步设计模式异步调用工作流。 有关详细信息,请参阅 异步编程概述

适用于

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

使用指定的 IDictionary<TKey,TValue> 输入参数、超时间隔 AsyncCallback和用户提供的状态异步调用工作流。

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>

工作流的输入参数字典,按参数名称进行键控。

timeout
TimeSpan

工作流在中止和 TimeoutException 引发工作流之前必须完成的间隔。

callback
AsyncCallback

工作流完成后要调用的方法。

state
Object

一个可选的特定于应用程序的对象,其中包含有关异步作的信息。

返回

对异步调用操作的引用。

示例

以下示例调用由活动组成的 LongRunningDiceRoll 工作流。 活动 LongRunningDiceRoll 具有两个输出参数,这些参数表示掷骰子操作的结果。 通过调用 EndInvoke来检索这些内容。 调用 EndInvoke 返回时,输出字典中会返回每个输出参数,按参数名称进行键键。

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该方法调用callback。 如果在 EndInvoke 工作流完成之前调用,则会阻止工作流完成。 如果工作流未在指定的超时间隔内完成,则会中止工作流,并在调用时TimeoutException引发一个EndInvoke工作流。

注释

仅在达到超时间隔且工作流在执行期间进入空闲状态时才会引发 TimeoutException。 如果工作流未进入空闲状态,那么完成时间超过指定超时间隔的工作流将会成功完成。

此方法使用 IAsyncResult 异步设计模式异步调用工作流。 有关详细信息,请参阅 异步编程概述

适用于