在發生FileSystemWatcher.Error
事件後,我不知道下一步該怎麼做。 異常可以是[比較]較小者,如從FileSystemWatcher錯誤中恢復的最佳做法是什麼?
一次在目錄
不影響觀看者的觀看過程中太多的變化,但它也可以是一個大問題 - 例如被監視的目錄被刪除,在這種情況下觀察者不再起作用。
我的問題是什麼是處理錯誤事件的最佳方式?
在發生FileSystemWatcher.Error
事件後,我不知道下一步該怎麼做。 異常可以是[比較]較小者,如從FileSystemWatcher錯誤中恢復的最佳做法是什麼?
一次在目錄
不影響觀看者的觀看過程中太多的變化,但它也可以是一個大問題 - 例如被監視的目錄被刪除,在這種情況下觀察者不再起作用。
我的問題是什麼是處理錯誤事件的最佳方式?
我只是簡單地得到內部異常類型,然後根據每個錯誤決定做什麼(重新啓動或失敗)。
所以
myWatcher.Error += new ErrorEventHandler(OnError);
Followde通過
private static void OnError(object source, ErrorEventArgs e)
{
if (e.GetException().GetType() == typeof(InternalBufferOverflowException))
{
// This can happen if Windows is reporting many file system events quickly
// and internal buffer of the FileSystemWatcher is not large enough to handle this
// rate of events. The InternalBufferOverflowException error informs the application
// that some of the file system events are being lost.
Console.WriteLine(("The file system watcher experienced an internal buffer overflow: " + e.GetException().Message));
}
}
我實際上通過使用阻塞隊列解決了所有的溢出問題 – Nissim 2012-07-26 10:15:05
的錯誤取決於肯定?
停止使用FileSystemWatcher,它不可靠寫入輪詢服務。 – saj 2012-07-26 10:11:06
我正在使用修改的FileSystemWatcher,它可以解決原始觀察者的大多數可靠性問題[溢出問題,重複事件和網絡路徑監視] – Nissim 2012-07-26 10:14:08
或者檢查屏幕上繪製和顯示之前發生的事件上的文件。適用於上下文菜單。 (編輯:聽起來不錯尼西,分享?:P) – negligible 2012-07-26 10:19:30