Note that there are some explanatory texts on larger screens.

plurals
  1. POFileSystemWatcher, unsubscribe from the event
    text
    copied!<p>I'm fooling around with the FileSystemWatcher in 4.0. I find this very useful but am getting caught in a loop. I'm trying to monitor whenever an ini is changed and change it back to the correct default (long story) however the change event copying over the new file is causing it to drop into a loop ... Any Ideas > ? I played around with the idea of deleting and recreating thefile to avoid triggering the changed event but this leads to another set of issues with the program that I'd rather avoid. Also I'd imagine I could overwrite the text but this also poses the same issue. Thanks in advance for the help</p> <pre><code> static void Main() { Watch (@"\\NoFault2010\Lexis\Data\Setup\", "tmconfig.ini", true); } static void Watch (string path, string filter, bool includeSubDirs) { using (var watcher = new FileSystemWatcher (path, filter)) { watcher.Changed += FileChanged; watcher.EnableRaisingEvents = true; Console.WriteLine("Do Not Close ... \n\nThis is a Temporary Configuration Manager for Time Matters ... \n\n\nI'm Listening ............"); Console.ReadLine(); } } static void FileChanged (object o, FileSystemEventArgs e) { string _right_stuff = @"\\NOFAULT2010\Lexis\Data\Templates\Programs\tmconfig.ini"; string _working = @"\\NOFAULT2010\Lexis\Data\Setup\tmconfig.ini"; System.Threading.Thread.Sleep(2000); File.Copy(_right_stuff, _working, true); Console.WriteLine("File {0} has been {1}", e.FullPath, e.ChangeType); MAIL_IT("SQLMail@lcjlawfirm.com", "TM Master.INI has been altered", "Check the Master INI and Yell At Ecopy Guy " + e.ChangeType + e.FullPath); } </code></pre> <p>How would I unsubscribe from the event to avoid entering into this loop.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload