I'm pretty sure that the
FileSystemWatcher
created in the
watch
method will be the value of the
sender
parameter of the
OnChanged
method.
In that case, it should be pretty simple:
private static void OnChanged(object sender, FileSystemEventArgs e)
{
FileSystemWatcher watcher = sender as FileSystemWatcher;
if (watcher == null)
return;
try
{
MessageBox.Show("File changed.");
watcher.EnableRaisingEvents = false;
}
finally
{
watcher.EnableRaisingEvents = true;
}
}