Async.AwaitIAsyncResult メソッド (F#)
更新 : 2010 年 8 月
IAsyncResult で待機する非同期計算を作成します。
名前空間/モジュール パス: Microsoft.FSharp.Control
アセンブリ: FSharp.Core (FSharp.Core.dll 内)
// Signature:
static member AwaitIAsyncResult : IAsyncResult * ?int -> Async<bool>
// Usage:
Async.AwaitIAsyncResult (iar)
Async.AwaitIAsyncResult (iar, millisecondsTimeout = millisecondsTimeout)
パラメーター
iar
型: IAsyncResult待機対象の IAsyncResult。
millisecondsTimeout
型: intタイムアウト値 (ミリ秒)。 指定しない場合は、Infinite に対応する既定値の -1。
戻り値
指定された IAsyncResult で待機する非同期計算。
解説
指定されたタイムアウト内でハンドルが結果を示した場合、この計算は true を返します。
使用例
Async.AwaitIAsyncResult を使用して、IAsyncResult を生成する .NET Framework の前の非同期操作が終了したときにトリガーされる計算を設定および実行する方法を次のコード例に示します。 この場合、AwaitIAsyncResult の呼び出しにより、操作は、ファイルの書き込み操作が完了するまで待機してから、ファイルを読み取るために開きます。
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 AwaitIAsyncResult to wait for the write operation
// to be completed before reading.
let readFile filename asyncResult count =
async {
let! returnValue = Async.AwaitIAsyncResult(asyncResult)
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 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
参照
参照
その他の技術情報
Microsoft.FSharp.Control 名前空間 (F#)
履歴の変更
日付 |
履歴 |
理由 |
---|---|---|
2010 年 8 月 |
コード例を追加。 |
情報の拡充 |