다음을 통해 공유


Async.StartChild<'T> 메서드(F#)

업데이트: 2010년 7월

비동기 워크플로 내에서 자식 계산을 시작합니다. 이렇게 하면 여러 비동기 계산을 동시에 실행할 수 있습니다.

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

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

// Signature:
static member StartChild : Async<'T> * ?int -> Async<Async<'T>>

// Usage:
Async.StartChild (computation)
Async.StartChild (computation, millisecondsTimeout = millisecondsTimeout)

매개 변수

  • computation
    형식: Async<'T>

    자식 계산입니다.

  • millisecondsTimeout
    형식: int

    제한 시간 값(밀리초)입니다. 이 값을 지정하지 않으면 Infinite에 해당하는 기본값 -1이 지정됩니다.

반환 값

입력 계산이 완료될 때까지 대기하는 새 계산입니다.

설명

이 메서드는 일반적으로 다음과 같이 F# 비동기 워크플로에서 let! 바인딩의 바로 오른쪽에 사용해야 합니다.

 async { 
    ...
    let! completor1 = childComputation1
    |> Async.StartChild
    let! completor2 = childComputation2
    |> Async.StartChild
    ... 
    let! result1 = completor1
    let! result2 = completor2
     ... }

이 방식으로 사용하면 StartChild를 사용할 때마다 childComputation의 인스턴스가 시작되고 연산이 완료될 때까지 대기할 계산을 나타내는 completor 개체가 반환됩니다. 실행 시 completor는 childComputation이 완료될 때까지 대기합니다.

예제

다음 코드 예제에서는 Async.StartChild를 사용하는 방법을 보여 줍니다.

open System.Windows.Forms

let bufferData = Array.zeroCreate<byte> 100000000

let asyncChild filename =
        async {
            printfn "Child job start: %s" filename
            use outputFile = System.IO.File.Create(filename)
            do! outputFile.AsyncWrite(bufferData)
            printfn "Child job end: %s " filename
        }

let asyncParent =
        async {
            printfn "Parent job start."
            let! childAsync1 = Async.StartChild(asyncChild "longoutput1.dat")
            let! childAsync2 = Async.StartChild(asyncChild "longoutput2.dat")
            let! result1 = childAsync1
            let! result2 = childAsync2
            printfn "Parent job end."
        }


let form = new Form(Text = "Test Form")
let button = new Button(Text = "Start")
form.Controls.Add(button)
button.Click.Add(fun args -> Async.Start(asyncParent)
                             printfn "Completed execution." )
Application.Run(form)

샘플 출력

작업이 동시에 실행되고 있으므로 출력이 인터리브됩니다.

        

플랫폼

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

참고 항목

참조

Control.Async 클래스(F#)

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

변경 기록

날짜

변경 내용

이유

2010년 7월

코드 예제를 추가했습니다.

향상된 기능 관련 정보