This topic has not yet been rated - Rate this topic

Async.Start Method (F#)

Updated: July 2010

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

Namespace/Module Path: Microsoft.FSharp.Control

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

// Signature:
static member Start : Async<unit> * ?CancellationToken -> unit

// Usage:
Async.Start (computation)
Async.Start (computation, cancellationToken = cancellationToken)
computation

Type: Async<unit>

The computation to run asynchronously.

cancellationToken

Type: CancellationToken

The cancellation token to be associated with the computation. If one is not supplied, the default cancellation token is used.

If no cancellation token is provided then the default cancellation token is used.

The following code example shows how to start an asynchronous computation on the thread pool.


open System.Windows.Forms

let bufferData = Array.zeroCreate<byte> 100000000

let async1 =
     async {
       use outputFile = System.IO.File.Create("longoutput.dat")
       do! outputFile.AsyncWrite(bufferData) 
     }


let form = new Form(Text = "Test Form")
let button = new Button(Text = "Start")
form.Controls.Add(button)
button.Click.Add(fun args -> Async.Start(async1))
Application.Run(form)


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

F# Runtime

Supported in: 2.0, 4.0

Silverlight

Supported in: 3

Date

History

Reason

July 2010

Added code example.

Information enhancement.

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ