Async.StartWithContinuations<'T> メソッド (F#)

更新 : 2010 年 7 月

非同期計算を実行し、現在のオペレーティング システムのスレッドですぐに開始します。 操作の完了時に、3 つの継続のうちの 1 つを呼び出します。

名前空間/モジュール パス: 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 月

コード例を追加。

情報の拡充