Proprietà MailboxProcessor.Error<'Msg> (F#)
Si verifica quando l'esecuzione dell'agente genera un'eccezione.
Percorso di spazio dei nomi/modulo: Microsoft.FSharp.Control
Assembly: FSharp.Core (in FSharp.Core.dll)
// Signature:
member this.Error : IEvent<Exception>
// Usage:
mailboxProcessor.Error
Valore restituito
L'evento di errore come oggetto che implementa IEvent.
Esempio
Nel codice riportato di seguito viene mostrato come utilizzare l'evento Error per gestire un'eccezione che si verifica nel corpo dell'agente.
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
Viene di seguito riportata una sessione di esempio.
Piattaforme
Windows 8, Windows 7, Windows Server 2012, Windows Server 2008 R2
Informazioni sulla versione
Versioni della libreria di base F#
Supportato in: 2,0, 4,0, portabile