FileSystemWatcher.Error 事件


FileSystemWatcher 的实例无法继续监视更改或内部缓冲区溢出时发生。Occurs when the instance of FileSystemWatcher is unable to continue monitoring changes or when the internal buffer overflows.

 event System::IO::ErrorEventHandler ^ Error;
public event System.IO.ErrorEventHandler Error;
member this.Error : System.IO.ErrorEventHandler 
Public Custom Event Error As ErrorEventHandler 


当某个事件阻止FileSystemWatcher对象监视更改时,将引发此事件。This event is raised whenever something prevents the FileSystemWatcher object from monitoring changes. 例如,如果对象正在监视远程目录中的更改,并且与该目录的连接丢失, Error则会引发事件。For example, if the object is monitoring changes in a remote directory and the connection to that directory is lost, the Error event is raised.

系统通知您文件发生了更改,并将这些更改存储在组件创建并传递给 Api 的缓冲区中。The system notifies you of file changes, and it stores those changes in a buffer that the component creates and passes to the APIs. 如果短时间内有很多更改,则缓冲区可能溢出。If there are many changes in a short time, the buffer can overflow. 这会使组件失去对目录中的更改的跟踪,并且它将只提供覆盖通知。This causes the component to lose track of changes in the directory, and it will only provide blanket notification. 增加缓冲区的大小会消耗大量资源,因为它来自无法换出到磁盘的非分页内存,因此使缓冲区尽可能小。Increasing the size of the buffer is expensive, because it comes from non paged memory that cannot be swapped out to disk, so keep the buffer as small as possible. 若要避免缓冲区溢出,请使用NotifyFilterFilterIncludeSubdirectories属性筛选出不需要的更改通知。To avoid a buffer overflow, use the NotifyFilter, Filter, and IncludeSubdirectories properties to filter out unwanted change notifications.


常见的文件系统操作可能会引发多个事件。Common file system operations might raise more than one event. 例如,将文件从一个目录移到另一个目录时,可能OnChanged会引发OnCreatedOnDeleted个和某些事件。For example, when a file is moved from one directory to another, several OnChanged and some OnCreated and OnDeleted events might be raised. 移动文件是一项复杂的操作,它包含多个简单操作,因此引发了多个事件。Moving a file is a complex operation that consists of multiple simple operations, therefore raising multiple events. 同样,某些应用程序(例如,防病毒软件)可能会导致检测到FileSystemWatcher其他文件系统事件。Likewise, some applications (for example, antivirus software) might cause additional file system events that are detected by FileSystemWatcher.