Async.StartWithContinuations<'T> — Metoda (F#)

Uruchamiane asynchroniczne obliczeń, natychmiast rozpoczynający bieżący wątek systemu operacyjnego.Wywołania jednej z trzech kontynuacji, po zakończeniu operacji.

Ścieżka obszaru nazw/modułu: Microsoft.FSharp.Control

Zestaw: FSharp.Core (w 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)

Parametry

  • computation
    Typ: asynchroniczne<'T>

    Asynchroniczne obliczeń do wykonania.

  • continuation
    Type: 'T -> unit

    Funkcja o nazwie na sukces.

  • exceptionContinuation
    Type: exn -> unit

    Funkcja o nazwie na wyjątek.

  • cancellationContinuation
    Type: OperationCanceledException -> unit

    Funkcja o nazwie na anulowanie.

  • cancellationToken
    Typ: CancellationToken

    Token opcjonalne anulowania skojarzenia z obliczeń.Jeśli ten parametr nie jest używany domyślny.

Uwagi

Warunkiem tokenu nie anulowanie domyślnego tokenu odwołania jest używany.

Przykład

Poniższy przykład kodu ilustruje użycie 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)

Platformy

Windows 8, Windows 7, Windows Server 2012 Windows Server 2008 R2

Informacje o wersji

F# Core wersji biblioteki

Obsługiwane: 2.0, 4.0, przenośne

Zobacz też

Informacje

Control.Async — Klasa (F#)

Microsoft.FSharp.Control — Przestrzeń nazw (F#)