次の方法で共有


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#)

履歴の変更

日付

履歴

理由

2011 年 1 月

コード例を追加。

情報の拡充