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);
}

适用于