Visual Studio 2010 - Visual F#
Control.Async Class (F#)

This static class holds members for creating and manipulating asynchronous computations.

Namespace/Module Path: Microsoft.FSharp.Control

Assembly: FSharp.Core (in FSharp.Core.dll)

[<Sealed>]
type Async =
 class
  static member AsBeginEnd : ('Arg -> Async<'T>) -> ('Arg * AsyncCallback * obj -> IAsyncResult) * (IAsyncResult -> 'T) * (IAsyncResult -> unit)
  static member AwaitEvent : IEvent<'Del,'T> * ?(unit -> unit) -> Async<'T>
  static member AwaitIAsyncResult : IAsyncResult * ?int -> Async<bool>
  static member AwaitTask : Task<'T> -> Async<'T>
  static member AwaitWaitHandle : WaitHandle * ?int -> Async<bool>
  static member CancelDefaultToken : unit -> unit
  static member Catch : Async<'T> -> Async<Choice<'T,exn>>
  static member FromBeginEnd : 'Arg1 * 'Arg2 * 'Arg3 * ('Arg1 * 'Arg2 * 'Arg3 * AsyncCallback * obj -> IAsyncResult) * (IAsyncResult -> 'T) * ?(unit -> unit) -> Async<'T>
  static member FromBeginEnd : 'Arg1 * 'Arg2 * ('Arg1 * 'Arg2 * AsyncCallback * obj -> IAsyncResult) * (IAsyncResult -> 'T) * ?(unit -> unit) -> Async<'T>
  static member FromBeginEnd : 'Arg1 * ('Arg1 * AsyncCallback * obj -> IAsyncResult) * (IAsyncResult -> 'T) * ?(unit -> unit) -> Async<'T>
  static member FromBeginEnd : (AsyncCallback * obj -> IAsyncResult) * (IAsyncResult -> 'T) * ?(unit -> unit) -> Async<'T>
  static member FromContinuations : (('T -> unit) * (exn -> unit) * (OperationCanceledException -> unit) -> unit) -> Async<'T>
  static member Ignore : Async<'T> -> Async<unit>
  static member OnCancel : (unit -> unit) -> Async<IDisposable>
  static member Parallel : seq<Async<'T>> -> Async<'T []>
  static member RunSynchronously : Async<'T> * ?int * ?CancellationToken -> 'T
  static member Sleep : int -> Async<unit>
  static member Start : Async<unit> * ?CancellationToken -> unit
  static member StartAsTask : Async<'T> * ?TaskCreationOptions * ?CancellationToken -> Task<'T>
  static member StartChild : Async<'T> * ?int -> Async<Async<'T>>
  static member StartChildAsTask : Async<'T> * ?TaskCreationOptions -> Async<Task<'T>>
  static member StartImmediate : Async<unit> * ?CancellationToken -> unit
  static member StartWithContinuations : Async<'T> * ('T -> unit) * (exn -> unit) * (OperationCanceledException -> unit) * ?CancellationToken -> unit
  static member SwitchToContext : SynchronizationContext -> Async<unit>
  static member SwitchToNewThread : unit -> Async<unit>
  static member SwitchToThreadPool : unit -> Async<unit>
  static member TryCancelled : Async<'T> * (OperationCanceledException -> unit) -> Async<'T>
  static member CancellationToken :  Async<CancellationToken>
  static member DefaultCancellationToken :  CancellationToken
 end
Remarks

This type is named FSharpAsync in the .NET assembly. If accessing the type from a .NET language other than F#, or through reflection, use this name.

For an overview of asynchronous workflows, see Asynchronous Workflows (F#).

Static Members

Member

Description

AsBeginEnd

Creates three functions that can be used to implement the .NET Asynchronous Programming Model (APM) for a given asynchronous computation.

AwaitEvent

Creates an asynchronous computation that waits for a single invocation of a CLI event by adding a handler to the event. Once the computation completes or is cancelled, the handler is removed from the event.

AwaitIAsyncResult

Creates an asynchronous computation that will wait on the IAsyncResult.

AwaitWaitHandle

Creates an asynchronous computation that will wait on the given WaitHandle.

CancelDefaultToken

Raises the cancellation condition for the most recent set of asynchronous computations started without any specific CancellationToken. Replaces the global CancellationTokenSource with a new global token source for any asynchronous computations created after this point without any specific CancellationToken.

CancellationToken

Creates an asynchronous computation that returns the CancellationToken governing the execution of the computation.

Catch

Creates an asynchronous computation that executes computation. If this computation completes successfully then return Choice1Of2 with the returned value. If this computation raises an exception before it completes then return Choice2Of2 with the raised exception.

DefaultCancellationToken

Gets the default cancellation token for executing asynchronous computations.

FromBeginEnd

Creates an asynchronous computation in terms of a Begin/End pair of actions in the style used in CLI APIs. This overlaod should be used if the operation is qualified by three arguments. For example, Async.FromBeginEnd(arg1,arg2,arg3,ws.BeginGetWeather,ws.EndGetWeather) When the computation is run, beginFunc is executed, with a callback which represents the continuation of the computation. When the callback is invoked, the overall result is fetched using endFunc.

FromBeginEnd

Creates an asynchronous computation in terms of a Begin/End pair of actions in the style used in CLI APIs. This overlaod should be used if the operation is qualified by two arguments. For example, Async.FromBeginEnd(arg1,arg2,ws.BeginGetWeather,ws.EndGetWeather) When the computation is run, beginFunc is executed, with a callback which represents the continuation of the computation. When the callback is invoked, the overall result is fetched using endFunc.

FromBeginEnd

Creates an asynchronous computation in terms of a Begin/End pair of actions in the style used in CLI APIs. This overlaod should be used if the operation is qualified by one argument. For example, Async.FromBeginEnd(place,ws.BeginGetWeather,ws.EndGetWeather) When the computation is run, beginFunc is executed, with a callback which represents the continuation of the computation. When the callback is invoked, the overall result is fetched using endFunc.

FromBeginEnd

Creates an asynchronous computation in terms of a Begin/End pair of actions in the style used in CLI APIs. For example, Async.FromBeginEnd(ws.BeginGetWeather,ws.EndGetWeather) When the computation is run, beginFunc is executed, with a callback which represents the continuation of the computation. When the callback is invoked, the overall result is fetched using endFunc.

FromContinuations

Creates an asynchronous computation that captures the current success, exception and cancellation continuations. The callback must eventually call exactly one of the given continuations.

Ignore

Creates an asynchronous computation that runs the given computation and ignores its result.

OnCancel

Generates a scoped, cooperative cancellation handler for use within an asynchronous workflow.

Parallel

Creates an asynchronous computation that executes all the given asynchronous computations, initially queueing each as work items and using a fork/join pattern.

RunSynchronously

Runs the asynchronous computation and await its result.

Sleep

Creates an asynchronous computation that will sleep for the given time. This is scheduled using a System.Threading.Timer object. The operation will not block operating system threads for the duration of the wait.

Start

Starts the asynchronous computation in the thread pool. Do not await its result.

StartChild

Starts a child computation within an asynchronous workflow. This allows multiple asynchronous computations to be executed simultaneously.

StartImmediate

Runs an asynchronous computation, starting immediately on the current operating system thread.

StartWithContinuations

Runs an asynchronous computation, starting immediately on the current operating system thread. Call one of the three continuations when the operation completes.

SwitchToContext

Creates an asynchronous computation that runs its continuation using syncContext.Post. If syncContext is null then the asynchronous computation is equivalent to SwitchToThreadPool().

SwitchToNewThread

Creates an asynchronous computation that creates a new thread and runs its continuation in that thread.

SwitchToThreadPool

Creates an asynchronous computation that queues a work item that runs its continuation.

TryCancelled

Creates an asynchronous computation that executes computation. If this computation is cancelled before it completes then the computation generated by running compensation is executed.

Platforms

Windows 7, Windows Vista SP2, Windows XP SP3, Windows XP x64 SP2, Windows Server 2008 R2, Windows Server 2008 SP2, Windows Server 2003 SP2

Version Information

F# Runtime

Supported in: 2.0, 4.0

Silverlight

Supported in: 3

See Also

Reference

Page view tracker