Async.Sleep メソッド (F#)
更新 : 2010 年 7 月
指定した時間スリープする非同期計算を作成します。 これは Timer オブジェクトを使用してスケジュールされます。 この操作では、待機中にオペレーティング システム スレッドがブロックされることはありません。
名前空間/モジュール パス: Microsoft.FSharp.Control
アセンブリ: FSharp.Core (FSharp.Core.dll)
// Signature:
static member Sleep : int -> Async<unit>
// Usage:
Async.Sleep (millisecondsDueTime)
パラメーター
millisecondsDueTime
型: intミリ秒数単位のスリープ時間。
例外
例外 |
状態 |
---|---|
時間の期限が負の値で、かつ無期限を示す値でない場合にスローされます。 |
戻り値
指定した時間スリープする非同期計算。
使用例
Async.Sleep を使用して、特定の期間に実行する計算をシミュレートする方法を次のコード例に示します。
let simulatedJob id time =
let timestamp() = System.DateTime.Now.Ticks
async {
printfn "Job %d start" id
let timestamp1 = timestamp()
do! Async.Sleep(time * 1000)
let timestamp2 = timestamp()
let timespan = System.TimeSpan(timestamp2 - timestamp1)
printfn "Job %d end %s" id (timespan.ToString("G"))
}
[ 1 .. 10]
|> List.mapi (fun index time -> simulatedJob index time)
|> Async.Parallel
|> Async.RunSynchronously
|> ignore
出力例
同時に実行されるスレッドが複数あるため、出力はインターリーブされます。
プラットフォーム
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 年 7 月 |
コード例を追加。 |
情報の拡充 |