0

S22.Imap ライブラリ ( https://github.com/smiley22/S22.Imap ) を使用して新しいメッセージをリッスンしようとしています。私は提供された例に従いましたが、助けが必要です...私が読んだことによると、ImapClient オブジェクトはバックグラウンドで待機し、(IDLE 機能を使用して) 新しいメッセージをリッスンし、新しいメッセージが発生したときにイベントを発生させる必要があります。受けます。そして、それはうまくいくようです...しばらくの間!Windows 7 Ultimate 64 ビットで Visual Studio 2010 を使用しています。私は単純な VB.NET Windows Forms プロジェクトを持っています - ここにコードがあります:

Imports S22.Imap

Public Class Form1

    Private Shared Sub UnhExceptionHandler(sender As Object, e As System.UnhandledExceptionEventArgs)
        Console.WriteLine("Unhandled UI Exception: {0}", DirectCast(e.ExceptionObject, Exception).Message)
    End Sub

    Private Shared Sub ThrExceptionHandler(sender As Object, e As System.Threading.ThreadExceptionEventArgs)
        Console.WriteLine("Unhandled Thread Exception: {0}", e.Exception.Message)
    End Sub

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf UnhExceptionHandler
        AddHandler System.Windows.Forms.Application.ThreadException, AddressOf ThrExceptionHandler
         Try
            Dim c As ImapClient = New ImapClient("imap.gmail.com", 993, "john@john-online.co.uk", "XXXXXXXXXXXXXXXX", AuthMethod.Login, True)
            ' Should ensure IDLE is actually supported by the server
            If c.Supports("IDLE") = False Then
                Console.WriteLine("Server does not support IMAP IDLE")
            Else
                ' We want to be informed when new messages arrive
                AddHandler c.NewMessage, New EventHandler(Of IdleMessageEventArgs)(AddressOf OnNewMessage)

            End If

        Catch ex As Exception
            MsgBox(ex.Message)

        End Try
    End Sub

    Private Shared Sub OnNewMessage(sender As Object, e As IdleMessageEventArgs)
        Console.WriteLine("A new message arrived. Message has UID: " & Convert.ToString(e.MessageUID))
    End Sub

End Class

これを実行すると、しばらくはすべてうまくいきます - 新しいメッセージの通知を受け取りますが、しばらくしてからネットワーク接続を切断して再接続すると、「UnhExceptionHandler()」に次のメッセージが表示されます。

Unable to read data from the transport connection: An established connection was aborted by the software in your host machine.

このコード例では、エラーをトラップして ImapCLient 接続を再起動するだけで済みます。しかし、これは S22.Imap ライブラリをテストするためのものです。多くのアカウントが同時にチェックされるアプリケーションで使用したいので、エラーをトラップして、どの ImapClient オブジェクトがそれを発生させたかを特定できるようにする必要がありますか?

誰でも可能な解決策を提案できますか?

4

0 に答える 0