FileSystemWatcher.OnDeleted(FileSystemEventArgs) FileSystemWatcher.OnDeleted(FileSystemEventArgs) FileSystemWatcher.OnDeleted(FileSystemEventArgs) FileSystemWatcher.OnDeleted(FileSystemEventArgs) Method

定義

引發 Deleted 事件。Raises the Deleted event.

protected:
 void OnDeleted(System::IO::FileSystemEventArgs ^ e);
protected void OnDeleted (System.IO.FileSystemEventArgs e);
member this.OnDeleted : System.IO.FileSystemEventArgs -> unit
Protected Sub OnDeleted (e As FileSystemEventArgs)

參數

備註

OnDeleted在受監視的目錄中刪除檔案或目錄時,會呼叫。OnDeleted is called when a file or directory, within the directory being monitored, is deleted.

某些常見的情況,例如複製或移動檔案或目錄,並不會直接對應至事件,但這些情況會導致引發事件。Some common occurrences, such as copying or moving a file or directory, do not correspond directly to an event, but these occurrences do cause events to be raised. 當您複製檔案或目錄時,如果正在監看Created該目錄,系統會在複製檔案的目錄中引發事件。When you copy a file or directory, the system raises a Created event in the directory to which the file was copied, if that directory is being watched. 如果您複製的來原始目錄正由另一個實例FileSystemWatcher監看,則不會引發任何事件。If the directory from which you copied was being watched by another instance of FileSystemWatcher, no event would be raised. 例如,您會建立兩個實例FileSystemWatcherFor example, you create two instances of FileSystemWatcher. FileSystemWatcher1 會設定為監看「C:\My 檔」,並將 FileSystemWatcher2 設定為監看「C:\Your 檔」。FileSystemWatcher1 is set to watch "C:\My Documents", and FileSystemWatcher2 is set to watch "C:\Your Documents". 如果您將檔案從「我的文件」複製到「您的檔」 Created ,則 FileSystemWatcher2 會引發事件,但不會針對 FileSystemWatcher1 引發任何事件。If you copy a file from "My Documents" into "Your Documents", a Created event will be raised by FileSystemWatcher2, but no event is raised for FileSystemWatcher1. 不同于複製,移動檔案或目錄會引發兩個事件。Unlike copying, moving a file or directory raises two events. 從上一個範例中,如果您將檔案從「我的文件」移至「您的檔Created 」,則 FileSystemWatcher2 會引發事件, Deleted而 FileSystemWatcher1 會引發事件。From the previous example, if you moved a file from "My Documents" to "Your Documents", a Created event would be raised by FileSystemWatcher2 and a Deleted event would be raised by FileSystemWatcher1.

引發事件會透過委派叫用此事件處理常式。Raising an event invokes the event handler through a delegate. 如需詳細資訊, 請參閱處理和引發事件For more information, see Handling and Raising Events.

給繼承者的注意事項

在衍生OnDeleted(FileSystemEventArgs)類別中覆寫時,請務必呼叫基類的OnDeleted(FileSystemEventArgs)方法。When overriding OnDeleted(FileSystemEventArgs) in a derived class, be sure to call the base class's OnDeleted(FileSystemEventArgs) method.

適用於

另請參閱