Share via


MailboxProcessor.Error<'Msg> 속성(F#)

에이전트 실행 결과 예외가 발생할 때 발생합니다.

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

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

// Signature:
member this.Error :  IEvent<Exception>

// Usage:
mailboxProcessor.Error

반환 값

IEvent를 구현하는 개체로서의 오류 이벤트입니다.

예제

다음 코드는 Error 이벤트를 사용하여 에이전트 본문에서 발생하는 예외를 처리하는 방법을 보여줍니다.

open System

type Message = string

let agent = MailboxProcessor<Message>.Start(fun inbox ->
    let rec loop n =
        async {
                let! message = inbox.Receive(10000);
                printfn "Message number %d. Message contents: %s" n message
                do! loop (n + 1)
        }
    loop 0)

agent.Error.Add(fun exn ->
    match exn with
    | :? System.TimeoutException as exn -> printfn "The agent timed out."
                                           printfn "Press Enter to close the program."
                                           Console.ReadLine() |> ignore
                                           exit(1)
    | _ -> printfn "Unknown exception.")

printfn "Mailbox Processor Test"
printfn "Type some text and press Enter to submit a message." 

while true do
    Console.ReadLine() |> agent.Post

다음 세션의 예를 참조하십시오.

  
  
  
  
  

플랫폼

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

버전 정보

F# 코어 라이브러리 버전

지원: 2.0, 4.0, 노트북

참고 항목

참조

Control.MailboxProcessor<'Msg> 클래스(F#)

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