Upraviť

Zdieľať cez


TaskToAsyncResult.Begin(Task, AsyncCallback, Object) Method

Definition

Creates a new IAsyncResult from the specified Task, optionally invoking callback when the task has completed.

public:
 static IAsyncResult ^ Begin(System::Threading::Tasks::Task ^ task, AsyncCallback ^ callback, System::Object ^ state);
public static IAsyncResult Begin (System.Threading.Tasks.Task task, AsyncCallback? callback, object? state);
static member Begin : System.Threading.Tasks.Task * AsyncCallback * obj -> IAsyncResult
Public Shared Function Begin (task As Task, callback As AsyncCallback, state As Object) As IAsyncResult

Parameters

task
Task

The Task to be wrapped in an IAsyncResult.

callback
AsyncCallback

The callback to be invoked upon task's completion. If null, no callback will be invoked.

state
Object

The state to be stored in the IAsyncResult.

Returns

An IAsyncResult to represent the task's asynchronous operation. This instance will also be passed to callback when it's invoked.

Exceptions

task is null.

Remarks

In conjunction with the End(IAsyncResult) or End<TResult>(IAsyncResult) methods, this method may be used to implement the Begin/End pattern (also known as the Asynchronous Programming Model pattern, or APM). It is recommended to not expose this pattern in new code; the methods on TaskToAsyncResult are intended only to help implement such Begin/End methods when they must be exposed, for example because a base class provides virtual methods for the pattern, or when they've already been exposed and must remain for compatibility. These methods enable implementing all of the core asynchronous logic via Tasks and then easily implementing Begin/End methods around that functionality.

Applies to