Share via


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

Führt eine asynchrone Berechnung aus, die sofort im aktuellen Betriebssystemthread beginnt. Rufen Sie eine der drei Fortsetzungen auf, sobald die Operation abgeschlossen ist.

Namespace/Modulpfad: Microsoft.FSharp.Control

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

// Signature:
static member StartWithContinuations : Async<'T> * ('T -> unit) * (exn -> unit) * (OperationCanceledException -> unit) * ?CancellationToken -> unit

// Usage:
Async.StartWithContinuations (computation, continuation, exceptionContinuation, cancellationContinuation)
Async.StartWithContinuations (computation, continuation, exceptionContinuation, cancellationContinuation, cancellationToken = cancellationToken)

Parameter

  • computation
    Typ: Async<'T>

    Die auszuführende asynchrone Berechnung.

  • continuation
    Typ: 'T -> unit

    Die bei Erfolg aufgerufene Funktion.

  • exceptionContinuation
    Typ: exn -> unit

    Die bei einer Ausnahme aufgerufene Funktion.

  • cancellationContinuation
    Typ: OperationCanceledException -> unit

    Die bei einem Abbruch aufgerufene Funktion.

  • cancellationToken
    Typ: CancellationToken

    Das optionale Abbruchtoken, das der Berechnung zugeordnet werden soll. Wenn dieser Parameter nicht bereitgestellt wird, wird der Standardwert verwendet.

Hinweise

Wenn kein Abbruchtoken bereitgestellt wird, wird das Standardabbruchtoken verwendet.

Beispiel

Das folgende Codebeispiel veranschaulicht die Verwendung von Async.StartWithContinuations.

open System.Windows.Forms

let bufferData = Array.zeroCreate<byte> 100000000

let async1 (label:System.Windows.Forms.Label) filename =
     Async.StartWithContinuations(
         async {
            label.Text <- "Operation started."
            use outputFile = System.IO.File.Create(filename)
            do! outputFile.AsyncWrite(bufferData)
            },
         (fun _ -> label.Text <- "Operation completed."),
         (fun _ -> label.Text <- "Operation failed."),
         (fun _ -> label.Text <- "Operation canceled."))



let form = new Form(Text = "Test Form")
let button1 = new Button(Text = "Start")
let button2 = new Button(Text = "Start Invalid", Top = button1.Height + 10)
let button3 = new Button(Text = "Cancel", Top = 2 * button1.Height + 20)
let label1 = new Label(Text = "", Width = 200, Top = 3 * button1.Height + 30)
form.Controls.AddRange [| button1; button2; button3; label1 |]
button1.Click.Add(fun args -> async1 label1 "longoutput.dat")
// Try an invalid filename to test the error case.
button2.Click.Add(fun args -> async1 label1 "|invalid.dat")
button3.Click.Add(fun args -> Async.CancelDefaultToken())
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: 2.0, 4.0

Silverlight

Unterstützt in: 3

Siehe auch

Weitere Ressourcen

Control.Async-Klasse (F#)

Microsoft.FSharp.Control-Namespace (F#)

Änderungsprotokoll

Datum

Versionsgeschichte

Grund

Juli 2010

Codebeispiel hinzugefügt.

Informationsergänzung.