다음을 통해 공유


Async.StartWithContinuations<'T> 메서드(F#)

업데이트: 2010년 7월

현재 운영 체제 스레드에서 즉시 시작되는 비동기 계산을 실행합니다. 연산이 완료되면 세 개의 연속 중 하나를 호출합니다.

네임스페이스/모듈 경로: Microsoft.FSharp.Control

어셈블리: FSharp.Core(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)

매개 변수

  • computation
    형식: Async<'T>

    실행할 비동기 계산입니다.

  • continuation
    형식: 'T -> unit

    성공 시 호출되는 함수입니다.

  • exceptionContinuation
    형식: exn -> unit

    예외 발생 시 호출되는 함수입니다.

  • cancellationContinuation
    형식: OperationCanceledException -> unit

    취소 시 호출되는 함수입니다.

  • cancellationToken
    형식: CancellationToken

    계산과 연결할 선택적 취소 토큰입니다. 이 매개 변수를 지정하지 않으면 기본값이 사용됩니다.

설명

취소 토큰을 지정하지 않으면 기본 취소 토큰이 사용됩니다.

예제

다음 코드 예제에서는 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)

플랫폼

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# 런타임

지원되는 버전: 2.0, 4.0

Silverlight

지원되는 버전: 3

참고 항목

참조

Control.Async 클래스(F#)

Microsoft.FSharp.Control 네임스페이스(F#)

변경 기록

날짜

변경 내용

이유

2010년 7월

코드 예제를 추가했습니다.

향상된 기능 관련 정보