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월 |
코드 예제를 추가했습니다. |
향상된 기능 관련 정보 |