FileSystemWatcher.Error 事件

定義

發生在 FileSystemWatcher 執行個體無法繼續執行監視變更時或在內部緩衝區溢位時。Occurs when the instance of FileSystemWatcher is unable to continue monitoring changes or when the internal buffer overflows.

public:
 event System::IO::ErrorEventHandler ^ Error;
[System.ComponentModel.Browsable(false)]
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.

適用於

另請參閱