Share via


MailboxProcessor.Error<'Msg>-Eigenschaft (F#)

Tritt auf, wenn die Ausführung der Agent-Ergebnisse eine Ausnahme ergibt.

Namespace/Modulpfad: Microsoft.FSharp.Control

Assembly: FSharp.Core (in FSharp.Core.dll)

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

// Usage:
mailboxProcessor.Error

Rückgabewert

Das Fehlerereignis als Objekt, das IEvent implementiert

Beispiel

Im folgenden Code wird veranschaulicht, wie mit dem Error-Ereignis eine Ausnahme behandelt wird, die im Text des Agent auftritt.

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

Eine Beispielsitzung folgt.

            

Plattformen

Windows 7, Windows Vista SP2, Windows XP SP3, Windows XP x64 SP2, Windows Server 2008 R2, Windows Server 2008 SP2, Windows Server 2003 SP2

Versionsinformationen

F#-Runtime

Unterstützt in: 2.0, 4.0

Silverlight

Unterstützt in: 3

Siehe auch

Weitere Ressourcen

Control.MailboxProcessor<'Msg>-Klasse (F#)

Microsoft.FSharp.Control-Namespace (F#)

Änderungsprotokoll

Datum

Versionsgeschichte

Grund

Januar 2011

Codebeispiel hinzugefügt.

Informationsergänzung.