title: Run another piece of code after stopping FileSystemWatcher
body: <p>I have a <code>FileSystemWatcher</code> code in C#, which detects files that have changed their content and it then copies these files to a specified directory (C:\Users\wost\Desktop\Data\files). After copying the files, so after <code>FileSystemWatcher</code> has stopped, I want to encrypt these files and I want to do this in the same program.
  So I have the following code in the main program:</p>
  <pre><code>Watcher w = new Watcher(lexpt, fexpt, userName);
  w.Watch();
  // Function which encrypts the files
  Encryption.EncryptFiles(@&quot;C:\Users\wost\Desktop\Data\files&quot;);
  </code></pre>
  <p>This doesn't work because the <code>FileSystemWatcher</code> will never stop, only if I quit the program. So, I decided to use a global variable <code>Global.serviceRunning</code> like shown in the code below, which stops <code>FileSystemWatcher</code> from watching in the specified directory:</p>
  <pre><code>public void Watch()
  {
      FileSystemWatcher watcher;
      using (watcher = new FileSystemWatcher(
          $&quot;C:\\Users\\wost\\AppData\\Roaming\\Sublime Text 3&quot;, _ext))
      {
  
          // Watch for changes in LastAccess and LastWrite times, and
          // the renaming of files or directories.
          watcher.NotifyFilter = NotifyFilters.LastAccess
                               | NotifyFilters.LastWrite
                               | NotifyFilters.FileName
                               | NotifyFilters.DirectoryName;
  
          // Only watch text files.
          // watcher.Filter = &quot;*.txt&quot;;
          watcher.IncludeSubdirectories = true;
          // Add event handlers.
          watcher.Changed += OnChanged;
          watcher.Created += OnChanged;
          watcher.Deleted += OnChanged;
          watcher.Renamed += OnRenamed;
  
          // Begin watching.
          watcher.EnableRaisingEvents = true;
          //GLOBAL VARIABLE
          while (Global.serviceRunning == true) ;
      }
  }
  </code></pre>
  <p>I have tried to change the value of this global variable to <code>false</code> in the main program, but it is not working. Can you please help me to find a way how to stop <code>FileSystemWatcher</code>, and then encrypt the files within the given directory?</p>