Async.AwaitWaitHandle メソッド (F#)

更新 : 2010 年 8 月

指定された WaitHandle を待機する非同期計算を作成します。

名前空間/モジュール パス: Microsoft.FSharp.Control

アセンブリ: FSharp.Core (FSharp.Core.dll 内)

// Signature:
static member AwaitWaitHandle : WaitHandle * ?int -> Async<bool>

// Usage:
Async.AwaitWaitHandle (waitHandle)
Async.AwaitWaitHandle (waitHandle, millisecondsTimeout = millisecondsTimeout)

パラメーター

  • waitHandle
    型: WaitHandle

    シグナル状態にすることができる待機ハンドル。

  • millisecondsTimeout
    型: int

    タイムアウト値 (ミリ秒)。 タイムアウト値を指定しない場合、既定値は -1 になります (System.Threading.Timeout.Infinite に対応)。

戻り値

指定された WaitHandle オブジェクトで待機する非同期計算。

解説

指定されたタイムアウト内でハンドルが結果を示した場合、この計算は true を返します。

使用例

Async.AwaitWaitHandle を使用して、待機ハンドルに従って別の非同期操作が完了したときに実行するように計算を設定する方法を次のコード例に示します。

open System.IO

let streamWriter1 = File.CreateText("test1.txt")
let count = 10000000
let buffer = Array.init count (fun index -> byte (index % 256)) 

printfn "Writing to file test1.txt."
let asyncResult = streamWriter1.BaseStream.BeginWrite(buffer, 0, count, null, null)

// Read a file, but use the waitHandle to wait for the write operation
// to be completed before reading.
let readFile filename waitHandle count = 
    async {
        let! returnValue = Async.AwaitWaitHandle(waitHandle)
        printfn "Reading from file test1.txt."
        // Close the file.
        streamWriter1.Close()
        // Now open the same file for reading.
        let streamReader1 = File.OpenText(filename)
        let! newBuffer = streamReader1.BaseStream.AsyncRead(count)
        return newBuffer
    }

let bufferResult = readFile "test1.txt" asyncResult.AsyncWaitHandle count
                   |> Async.RunSynchronously

出力

      

プラットフォーム

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 年 8 月

コード例を追加。

情報の拡充