I am just wondering is there anyway to turn on and off for EnableRaisingEvents every 100 milliseconds? For example, initially, the EnableRaisingEvents is set true. when there is an event coming in, EnableRaisingEvents is set to false. 100 milliseconds after, EnableRaisingEvents is set true again. Until the file watcher receive another event, EnableRaisingEvents is set false again. It is OK to miss events during the time that EnableRaisingEvents is turn off (set as false). So I am just wondering how should I realize this logic in code. What confuses me is, the event is going to be fired anyway, should I use a tick to decide whether to accept this event or not?
You might try something like this (edited with Austin Salonen's suggestion):
private static Timer _myTimer = new Timer();
// ...
private static void OnTick(Object obj, EventArgs args)
{
fileSystemWatcher.EnableRaisingEvents ^= true;
}
// ...
_myTimer.Tick += OnTick;
_myTimer.Interval = 100;
_myTimer.Start();