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 的呼叫傳回時,每個輸出引數都會傳入 outputs 字典 (以引數名稱做為索引鍵)。

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 的呼叫傳回時,每個輸出引數都會傳入 outputs 字典 (以引數名稱做為索引鍵)。

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

工作流程必須在其中止並擲回 TimeoutException 前完成的間隔。

callback
AsyncCallback

在工作流程完成時所要呼叫的方法。

state
Object

選擇性的應用程式特定物件,其中包含非同步作業的相關資訊。

傳回

非同步叫用作業的參考。

範例

下列範例會叫用由 LongRunningDiceRoll 活動組成的工作流程。 LongRunningDiceRoll 活動具有兩個輸出引數,這些引數代表擲骰作業的結果。 您可以透過呼叫 EndInvoke,擷取這些引數。 當 EndInvoke 的呼叫傳回時,每個輸出引數都會傳入 outputs 字典 (以引數名稱做為索引鍵)。

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 的呼叫傳回時,每個輸出引數都會傳入 outputs 字典 (以引數名稱做為索引鍵)。

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 非同步設計模式,以非同步方式叫用工作流程。 如需詳細資訊,請參閱 異步程序設計概觀

適用於