在一個正常工作的網絡中,您不應該有任何與丟失事件相關的錯誤,但您應該意識到網絡上的簡單呃逆會導致您的FileSystemWatcher監控無效。
與網絡共享連接的瞬間下降將觸發FileSystemWatcher中的錯誤,即使連接將重新建立,FileSystemWatcher也不會再收到任何通知。
這是MSDN
static void Main()
{
// Create a new FileSystemWatcher and set its properties.
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = @"\\yourserver\yourshare";
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
// Only watch text files.
watcher.Filter = "*.txt";
// Add handler for errors.
watcher.Error += new ErrorEventHandler(OnError);
// Begin watching.
watcher.EnableRaisingEvents = true;
// Wait for the user to quit the program.
Console.WriteLine("Press \'q\' to quit the sample.");
while(Console.Read()!='q');
}
private static void OnError(object source, ErrorEventArgs e)
{
// Show that an error has been detected.
Console.WriteLine("The FileSystemWatcher has detected an error");
// Give more information if the error is due to an internal buffer overflow.
Type t = e.GetException().GetType();
Console.WriteLine(("The file system watcher experienced an error of type: " +
t.ToString() + " with message=" + e.GetException().Message));
}
發現如果您嘗試啓動這個控制檯應用程序,然後關閉您的網絡連接,你會看到Win32Exception一個sligtly改編的例子,但如果你再這樣做,沒有更多的錯誤事件將由正在運行的FileSystemWatcher看到
您的問題與其標題有什麼關係?我沒有看到有關緩衝區溢出的任何信息。 –
使用默認緩衝區大小,絕對最差的情況是它可以存儲15個事件。更典型的是大約30或40,這取決於文件路徑名的長度。這當然不會對每天發生兩次的重命名事件進行測試。 –
@Hans Passant是否所有'FileSystemWatcher'都使用相同的緩衝區? – Cheetah