Async.SwitchToNewThread 메서드(F#)

새 스레드를 만들고 이 스레드에서 해당 연속을 실행하는 비동기 계산을 만듭니다.

네임스페이스/모듈 경로: Microsoft.FSharp.Control

어셈블리: FSharp.Core(FSharp.Core.dll)

// Signature:
static member SwitchToNewThread : unit -> Async<unit>

// Usage:
Async.SwitchToNewThread ()

반환 값

새 스레드에서 실행할 계산입니다.

예제

다음 코드 예제에서는 Async.SwitchToNewThreadAsync.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 Windows 서버 2012, Windows Server 2008 R2, Windows 7, 8

버전 정보

F# 코어 라이브러리 버전

지원: 2.0, 4.0, 노트북

참고 항목

참조

Control.Async 클래스(F#)

Microsoft.FSharp.Control 네임스페이스(F#)