Disposing of FileSystemWatcher

后端 未结 2 1830
南方客
南方客 2020-12-17 02:46

So my understanding is that whenever using a class that implements IDisposable, it\'s parent also needs to implement IDisposable interface. (FileWatcher using FileSystemWatc

2条回答
  •  离开以前
    2020-12-17 03:19

    When shutting down an application, run the dispose method.

    According to the method requested, when you want to dispose of something when your shutting down the program.

    if you are using a class via, then IDisposable is for disposing the class object, but essentially you still might want to do it when you are shutting down the program

    bool myFlag = false;
    private FileSystemWatcher watcher;
    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
     {
               myFlag = true;
               if(myFlag)
               watcher.Dispose(); //Your FileSystemWatcher object
     }
    

提交回复
热议问题