WorkflowInvoker.BeginInvoke 方法

定義

使用 IAsyncResult 非同步設計模式,非同步地呼叫工作流程。

多載

名稱 Description
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 在工作流程完成前呼叫,則會阻塞直到工作流程完成。 若要設定工作流程必須完成的逾時間隔,請使用其中一種佔用 BeginInvoke的超載。TimeSpan

此方法透過非 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 在工作流程完成前呼叫,則會阻塞直到工作流程完成。 若要設定工作流程必須完成的逾時間隔,請使用其中一種佔用 BeginInvoke的超載。TimeSpan

此方法透過非 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

工作流程必須完成的間隔,然後才會中止並拋出 a 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拋出 aEndInvoke

Note

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

工作流程必須完成的間隔,然後才會中止並拋出 a 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會拋出 aEndInvoke

Note

TimeoutException只有在逾時間隔經過且工作流程在執行期間變成閑置時,才會擲回 。 如果工作流程未閑置,花費的時間超過指定的超時時間間隔才能順利完成的工作流程。

此方法透過非 IAsyncResult 同步設計模式非同步啟動工作流程。 欲了解更多資訊,請參閱 非同步程式概述

適用於