private static void DeviceWatcher_DeviceQueryRemove(object sender, DeviceNotificationEventArgs e) { if (DirectoryWatchers.ContainsKey(e.Name)) { DirectoryWatchers[e.Name].Stop(); } }
private static void DeviceWatcher_DeviceArrived(object sender, DeviceNotificationEventArgs e) { if (DirectoryWatchers.ContainsKey(e.Name)) { DirectoryWatchers[e.Name].Start(); } else { RegisterDirectoryWatcher(e.Name); } SendNotificationMessage(NotificationType.Add, e.Name); }
public static void RegisterDirectoryWatcher(string path) { DirectoryWatcher directoryWatcher = new DirectoryWatcher(path, OnFileEvent, OnError); directoryWatcher.Start(); if (DirectoryWatchers.ContainsKey(path)) { DirectoryWatchers[path].Stop(); DirectoryWatchers.Remove(path); } DirectoryWatchers.Add(path, directoryWatcher); }