我有一個服務可以打開多個觀察者來觀察多個文件夾。在觀看文件夾一段時間後,我收到「網絡BIOS命令限制已達到」。c#服務「netwerk bios命令限制已達到」錯誤原因和最佳解決方案是什麼?
當我在here上閱讀時,這是由於長時間的請求超出允許範圍而造成的。
我相信這是由於下面的錯誤處理代碼我有,這是由觀察者錯誤事件觸發的。這通過再次調用WatchFile方法來啓動觀察器的新實例。我相信這會讓現在不存在的老觀察者繼續運行,並啓動一個新的觀察者,但是我恐怕停止觀察者可能會阻止它再次啓動它,或者將停止基於觀察者的所有實例。
或者我錯了,是錯誤依賴於更改的數量?這會導致100個文件同時進入以導致此錯誤。
我想停止並開始服務,每當我在這個錯誤運行,但這不會解決問題本身,但只是隱藏它。有更好的解決方案嗎?
private static void watcherError(String directory, Boolean intray, ErrorEventArgs e, FileSystemWatcher watcher)
{
Exception watchException = e.GetException();
EventLog.WriteEntry("WhiteFileMover", String.Concat("error gedetecteerd, watcher werd herstart - ", watchException.Message), EventLogEntryType.Information);
watcher = new FileSystemWatcher();
while (!watcher.EnableRaisingEvents)
{
try
{
// This will throw an error at the
// watcher.NotifyFilter line if it can't get the path.
WatchFile(directory, intray);
}
catch(Exception exp)
{
// Sleep for a bit; otherwise, it takes a bit of
// processor time
EventLog.WriteEntry("WhiteFileMover", String.Concat("Failed to restart watcher, retrying in 5 seconds - ", exp.Message), EventLogEntryType.Warning);
System.Threading.Thread.Sleep(5000);
}
}
}
如何處置遇到錯誤的舊觀察者? – Kolja 2012-01-30 14:13:53
@Kolja如果我做watcher.dispose,那隻能處理那個實例或基於觀察者的所有實例嗎?因爲我已經創建了3個觀察者實例,但只想處理其中的一個。 – Andy 2012-01-30 14:25:46
它會處理變量指向的當前實例,這是失敗的實例。之後,您可以創建一個新的實例。但是你不會去處理它,只是創建一個新的,最終可能會有一堆浪費的觀察者實例。 – Kolja 2012-01-31 10:13:02