共用方式為


AsyncCodeActivity.BeginExecute 方法

定義

在衍生類別中實作及使用指定的執行內容、回呼方法和使用者狀態時,將非同步活動加入執行階段工作流程中的佇列。

protected:
 abstract IAsyncResult ^ BeginExecute(System::Activities::AsyncCodeActivityContext ^ context, AsyncCallback ^ callback, System::Object ^ state);
protected abstract IAsyncResult BeginExecute (System.Activities.AsyncCodeActivityContext context, AsyncCallback callback, object state);
abstract member BeginExecute : System.Activities.AsyncCodeActivityContext * AsyncCallback * obj -> IAsyncResult
Protected MustOverride Function BeginExecute (context As AsyncCodeActivityContext, callback As AsyncCallback, state As Object) As IAsyncResult

參數

context
AsyncCodeActivityContext

定義 AsyncCodeActivity 之執行環境的資訊。

callback
AsyncCallback

在非同步活動和完成通知發生後所呼叫的方法。

state
Object

儲存非同步活動之執行個體的變數資訊的物件。

傳回

儲存非同步活動執行個體之變數資訊的物件。

範例

下列範例將示範如何在自訂活動中覆寫 BeginExecute 方法。

protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
{
    string tempFileName = Path.GetTempFileName();
    Console.WriteLine("Writing to file: " + tempFileName);

    FileStream file = File.Open(tempFileName, FileMode.Create);

    context.UserState = file;

    byte[] bytes = UnicodeEncoding.Unicode.GetBytes("123456789");
    return file.BeginWrite(bytes, 0, bytes.Length, callback, state);
}

適用於