2

私はスタンドアロンアプリケーションvb.net(2.0)を使用しており、filesysystem watcherクラスを使用して、指定されたディレクトリに入る新しいxmlを見つけ、アプリケーションはそのファイルを取得してプロセスを続行しますが、ディレクトリはネットワークマシンにあります。

今私の問題は

パスが使用できなくなったら、共有パスサーバーがオフラインになることを意味します。その後、アプリケーションが私を統合しません。コードを変更するにはどうすればよいですか。

誰でもアイデアがあります、私に共有してください

事前にありがとうNanda.A

4

1 に答える 1

2

ディレクトリの変更をリッスンしていて、それが使用できなくなった場合 (サーバーの再起動など)、FileSystemWatcher は例外をスローします。これは、リッスンできるOnError イベントを提供し、問題の処理方法を決定できます。

複数のウォッチャーを実行するアプリケーションがあり、1 つのエラーが発生すると、アプリケーションは 30 秒ごとにループして再度接続を試みてエラーを処理します。また、接続に失敗し、最終的に (約 1 時間後に) 接続をあきらめた回数の現在までの合計を保持します。

VB.Net の一般的な考え方は次のとおりです。

''' <summary>
''' This event is called when an error occurs with the file watcher. Most likely the directory being watched is no longer available (probably from a server reboot.)
''' </summary>
Protected Sub Scan_Error(ByVal Source As FileSystemWatcher, ByVal E As ErrorEventArgs)

    '// Stop listening
    Source.EnableRaisingEvents = False

    '// Maximum attempts before shutting down (one hour)
    Dim Max_Attempts As Integer = 120
    Dim Timeout As Integer = 30000
    Dim I As Integer = 0

    '// Attempt to listen - if fail, wait and try again in 30 seconds.
    While Source.EnableRaisingEvents = False And I < Max_Attempts
        I += 1

        Try
            Source.EnableRaisingEvents = True
        Catch
            Source.EnableRaisingEvents = False
            System.Threading.Thread.Sleep(Timeout)
        End Try
    End While
End Sub
于 2010-01-31T19:48:07.910 に答える