title: Do I need to keep a reference to a FileSystemWatcher?
body: <p>I'm using a <code>FileSystemWatcher</code> (in an ASP.NET web app) to monitor a file for changes. The watcher is set up in the constructor of a Singleton class, e.g:</p>
  
  <pre><code>private SingletonConstructor()
  {
      var fileToWatch = "{absolute path to file}";
      var fsw = new FileSystemWatcher(
          Path.GetDirectoryName(fileToWatch),
          Path.GetFileName(fileToWatch));
      fsw.Changed += OnFileChanged;
      fsw.EnableRaisingEvents = true;
  }
  
  private void OnFileChanged(object sender, FileSystemEventArgs e)
  {
      // process file...
  }
  </code></pre>
  
  <p>Everything works fine so far. But my question is:</p>
  
  <p>Is it safe to setup the watcher using a local variable (<code>var fsw</code>)? Or should I keep a reference to it in a private field to prevent it from being garbage collected?</p>