private void WaitForChange(object state, bool timedOut) { bool flag = false; lock (this.NotificationLock) { this.RegisteredWait.Unregister(null); this.RegisteredWait = null; if (this.NotificationHandle.IsValid && this.NotificationHandle.Next()) { this.RegisteredWait = ThreadPool.RegisterWaitForSingleObject(this.NotificationHandle, new WaitOrTimerCallback(this.WaitForChange), null, -1, true); flag = true; } else { this.NotificationHandle.Close(); this.NotificationHandle = null; } } if (flag) { this.OnChanged(EventArgs.Empty); } }
private void Restart() { lock (this.NotificationLock) { this.Stop(); this.NotificationHandle = new NotificationWaitHandle(this.FPath, this.FWatchSubdirs, this.FFilter); if (!this.NotificationHandle.Start()) { this.NotificationHandle = null; } else { this.RegisteredWait = ThreadPool.RegisterWaitForSingleObject(this.NotificationHandle, new WaitOrTimerCallback(this.WaitForChange), null, -1, true); } } }
private void Stop() { lock (this.NotificationLock) { if (this.RegisteredWait != null) { this.RegisteredWait.Unregister(null); } this.RegisteredWait = null; if (this.NotificationHandle != null) { this.NotificationHandle.Close(); } this.NotificationHandle = null; } }