System.Threading.Tasks.TaskFactory.FromAsync Method

Creates a System.Threading.Tasks.Task that represents a pair of begin and end methods that conform to the Asynchronous Programming Model pattern.

Syntax

public Task FromAsync (Func<AsyncCallback, object, IAsyncResult> beginMethod, Action<IAsyncResult> endMethod, object state, TaskCreationOptions creationOptions)

Parameters

beginMethod
The delegate that begins the asynchronous operation.
endMethod
The delegate that ends the asynchronous operation.
state
An object containing data to be used by the beginMethod delegate.
creationOptions
The TaskCreationOptions value that controls the behavior of the created System.Threading.Tasks.Task.

Returns

The created System.Threading.Tasks.Task that represents the asynchronous operation.

Remarks

The beginMethod delegate is started on the thread that erload:System.Threading.Tasks.TaskFactory.FromAsync is running on. This method throws any exceptions thrown by the beginMethod. The System.Threading.Tasks.TaskCreationOptions values TaskCreationOptions.PreferFairness, TaskCreationOptions.LongRunning and TaskCreationOptions.AttachedToParent are all mutually exclusive. In the FromAsync methods, either LongRunning or AttachedToParent by themselves will cause an ArgumentOutOfRangeException to be thrown.

Requirements

Namespace: System.Threading.Tasks
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 4.0.0.0