Share via


Async.StartAsTask<'T>-Methode (F#)

Aktualisiert: August 2010

Führt eine Berechnung im Threadpool aus. Gibt Task zurück, der im entsprechenden Zustand abgeschlossen wird, sobald die Berechnung beendet wird (das Ergebnis liefert, eine Ausnahme auslöst oder abgebrochen wird). Wenn kein Abbruchtoken bereitgestellt wird, wird das Standardabbruchtoken verwendet.

Namespace/Modulpfad: Microsoft.FSharp.Control

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

// Signature:
static member StartAsTask : Async<'T> * ?TaskCreationOptions * ?CancellationToken -> Task<'T>

// Usage:
Async.StartAsTask (computation)
Async.StartAsTask (computation, taskCreationOptions = taskCreationOptions, cancellationToken = cancellationToken)

Parameter

  • computation
    Typ: Async<'T>

    Die auszuführende Berechnung.

  • taskCreationOptions
    Typ: TaskCreationOptions

    Optionale Aufgabenerstellungsoptionen.

  • cancellationToken
    Typ: CancellationToken

    Optionales Abbruchtoken.

Rückgabewert

Ein Task<TResult>-Objekt, das die angegebene Berechnung darstellt.

Beispiel

Im folgenden Codebeispiel wird die Verwendung von Async.StartAsTask veranschaulicht.

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 -> let task = Async.StartAsTask(async1)
                             printfn "Do some other work..."
                             task.Wait()
                             printfn "done")
Application.Run(form)

Plattformen

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

Versionsinformationen

F#-Runtime

Unterstützt in: 4.0

Silverlight

Nicht unterstützt

Siehe auch

Weitere Ressourcen

Control.Async-Klasse (F#)

Microsoft.FSharp.Control-Namespace (F#)

Änderungsprotokoll

Datum

Versionsgeschichte

Grund

August 2010

Codebeispiel hinzugefügt.

Informationsergänzung.