MailboxProcessor.Error<'Msg> 屬性 (F#)
更新:2011 年 1 月
執行代理程式而造成例外狀況時發生。
命名空間/模組路徑: 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 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.MailboxProcessor<'Msg> 類別 (F#)
Microsoft.FSharp.Control 命名空間 (F#)
變更記錄
日期 |
History |
原因 |
---|---|---|
2011 年 1 月 |
加入程式碼範例。 |
資訊加強。 |