public void CreateFileWatcher(string path, SiteSetupManager setupManager) { SetupManager = setupManager; FileSystemWatcher watcher = new FileSystemWatcher(); ResetEvent = new ManualResetEvent(false); watcher.Path = path; /* Watch for changes in LastAccess and LastWrite times, and * the renaming of files or directories. */ watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName; watcher.IncludeSubdirectories = true; // Add event handlers. watcher.Changed += new FileSystemEventHandler(FileChange); watcher.Created += new FileSystemEventHandler(FileChange); // Begin watching. watcher.EnableRaisingEvents = true; ChangedFilesInIteration = new List <string>(); while (true) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Watching for changes to files in Sherpa content directory..."); Console.ResetColor(); if (ResetEvent.WaitOne()) { SetupManager.UploadChangedFiles(); ChangedFilesInIteration.Clear(); ResetEvent.Reset(); } else { Console.WriteLine("Waiting timed-out"); } } //watcher.WaitForChanged(WatcherChangeTypes.Changed | WatcherChangeTypes.Created | WatcherChangeTypes.Renamed, -1); }