다음을 통해 공유


Async.StartImmediate 메서드(F#)

업데이트: 2010년 8월

현재 운영 체제 스레드에서 즉시 시작되는 비동기 계산을 실행합니다.

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

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

// Signature:
static member StartImmediate : Async<unit> * CancellationToken option -> unit

// Usage:
Async.StartImmediate (computation)
Async.StartImmediate (computation, cancellationToken = cancellationToken)

매개 변수

  • computation
    형식: Async<unit>

    실행할 비동기 계산입니다.

  • cancellationToken
    형식: CancellationToken

    계산과 연결할 선택적 취소 토큰입니다. 이 매개 변수를 지정하지 않으면 기본값이 사용됩니다.

설명

취소 토큰을 지정하지 않으면 기본 취소 토큰이 사용됩니다.

예제

다음 코드 예제에서는 Async.StartImmediate를 사용하여 현재 스레드에서 비동기 계산을 시작하는 방법에 대해 설명합니다. 비동기 작업은 UI 스레드에서 UI를 자주 업데이트해야 합니다. UI를 업데이트하여 비동기 작업을 시작해야 하는 경우 스레드 풀 스레드에서 비동기 작업을 시작하는 Async.Start보다 Async.StartImmediate를 선택하는 것이 더 좋습니다.


open System.Windows.Forms

let bufferData = Array.zeroCreate<byte> 100000000

let async1 (button : Button) =
     async {
       button.Text <- "Busy"
       button.Enabled <- false
       let context = System.Threading.SynchronizationContext.Current
       do! Async.SwitchToThreadPool()
       use outputFile = System.IO.File.Create("longoutput.dat")
       do! outputFile.AsyncWrite(bufferData)
       do! Async.SwitchToContext(context)
       button.Text <- "Start"
       button.Enabled <- true
     }


let form = new Form(Text = "Test Form")
let button = new Button(Text = "Start")
form.Controls.Add(button)
button.Click.Add(fun args -> Async.StartImmediate(async1 button))
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년 8월

향상된 코드 예.

향상된 기능 관련 정보