/// <summary> /// Method is used to walk the file system and check files for against /// </summary> private static void monitorChanges() { while (true) { string[] stalkedFiles = null; lock (_StateLock) { stalkedFiles = new string[_State.Count]; _State.Keys.CopyTo(stalkedFiles, 0); } try { foreach (string StalkedFile in stalkedFiles) { FileState state = null;// _State[StalkedFile]; bool found = false; lock (_StateLock) { found = _State.TryGetValue(StalkedFile, out state); } if (!found) { if (log.IsWarnEnabled) { log.WarnFormat("\"{0}\" was marked as a stalked file but was not found in _state??? Skipping...", StalkedFile); } continue; } try { FileInfo file = new FileInfo(StalkedFile); if (!state.Equals(file)) { state.Update(file); state.Notify(); } } catch (Exception ex0) { log.Warn("Exception thrown", ex0); } //Sleep between each iteration to spread the operations over a couple seconds. Thread.Sleep(1000); } Thread.Sleep(MAX_NOTIFICATION_FREQUENCY); } catch (Exception ex) { log.Warn("Exception thrown", ex); } } }