다음을 통해 공유


Async.AwaitIAsyncResult 메서드(F#)

IAsyncResult에서 대기하는 비동기 계산을 만듭니다.

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

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

// Signature:
static member AwaitIAsyncResult : IAsyncResult * ?int -> Async<bool>

// Usage:
Async.AwaitIAsyncResult (iar)
Async.AwaitIAsyncResult (iar, millisecondsTimeout = millisecondsTimeout)

매개 변수

  • iar
    형식: IAsyncResult

    대기할 IAsyncResult입니다.

  • millisecondsTimeout
    형식: int

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

반환 값

지정된 IAsyncResult에서 대기하는 비동기 계산입니다.

설명

핸들에서 지정된 제한 시간 내에 결과를 표시하면 계산에서 true를 반환합니다.

예제

다음 코드 예제에서는 Async.AwaitIAsyncResult를 사용하여 IAsyncResult를 생산하는 이전 .NET Framework 비동기 작업이 완료되면 트리거되는 계산을 설정 및 실행하는 방법에 대해 보여줍니다. 이 경우 AwaitIAsyncResult에 대한 호출에서는 파일을 읽기용으로 열기 전에 파일 쓰기 작업을 완료할 때까지 기다립니다.

open System.IO

let streamWriter1 = File.CreateText("test1.txt")
let count = 10000000
let buffer = Array.init count (fun index -> byte (index % 256)) 

printfn "Writing to file test1.txt." 
let asyncResult = streamWriter1.BaseStream.BeginWrite(buffer, 0, count, null, null)

// Read a file, but use AwaitIAsyncResult to wait for the write operation 
// to be completed before reading. 
let readFile filename asyncResult count = 
    async {
        let! returnValue = Async.AwaitIAsyncResult(asyncResult)
        printfn "Reading from file test1.txt." 
        // Close the file.
        streamWriter1.Close()
        // Now open the same file for reading. 
        let streamReader1 = File.OpenText(filename)
        let! newBuffer = streamReader1.BaseStream.AsyncRead(count)
        return newBuffer
    }

let bufferResult = readFile "test1.txt" asyncResult count
                   |> Async.RunSynchronously

플랫폼

Windows Windows 서버 2012, Windows Server 2008 R2, Windows 7, 8

버전 정보

F# 코어 라이브러리 버전

지원: 2.0, 4.0, 노트북

참고 항목

참조

Control.Async 클래스(F#)

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

IAsyncResult