Async.SwitchToNewThread メソッド (F#)
更新 : 2010 年 7 月
新しいスレッドを作成し、そのスレッドで継続を実行する非同期計算を作成します。
名前空間/モジュール パス: Microsoft.FSharp.Control
アセンブリ: FSharp.Core (FSharp.Core.dll 内)
// Signature:
static member SwitchToNewThread : unit -> Async<unit>
// Usage:
Async.SwitchToNewThread ()
戻り値
新しいスレッドで実行する計算。
使用例
次に、Async.SwitchToNewThread および Async.SwitchToThreadPool を使用して、同期メソッド呼び出しを非同期メソッドとしてラップするコード例を示します。
open System
open System.IO
let asyncMethod f =
async {
do! Async.SwitchToNewThread()
let result = f()
do! Async.SwitchToThreadPool()
return result
}
let GetFilesAsync(path) = asyncMethod (fun () -> Directory.GetFiles(path))
let listFiles path =
async {
let! files = GetFilesAsync(path)
Array.iter (fun elem -> printfn "%s" elem) files
}
printfn "Here we go..."
// The output is interleaved, which shows that these are both
// running simultaneously.
Async.Start(listFiles ".")
Async.Start(listFiles ".")
Console.WriteLine("Press a key to continue...")
Console.ReadLine() |> 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 月 |
コード例を追加。 |
情報の拡充 |