我现在一次监视一个文件夹,我想知道如何同时进行文件监视three folders
。
请在下面查看我的更新代码,我想知道我是否应该
给出m_Watcher.Path = draft;
这 三行m_Watcher.Path = release;
m_Watcher.Path = archive;
我的代码:
Dictionary<string, FileSystemWatcher> monitor = new Dictionary<string, FileSystemWatcher>();
public void monitorFolder(string folderPath)
{
string draft = ini.ReadValue("Location", "Draft");
string release = ini.ReadValue("Location", "Release");
string archive = ini.ReadValue("Location", "Archive");
// System.IO.Directory.CreateDirectory(draft); // no need to check if exists
if (monitor.ContainsKey(draft)) return; //if directory already being monitored
if (monitor.ContainsKey(release)) return;
if (monitor.ContainsKey(archive)) return;
m_Watcher = new System.IO.FileSystemWatcher();
m_Watcher.Filter = "*.*";
m_Watcher.Path = folderPath; //give the folderpath
m_Watcher.IncludeSubdirectories = true;
m_Watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
m_Watcher.Changed += new FileSystemEventHandler(OnChanged);
m_Watcher.Created += new FileSystemEventHandler(OnChanged);
m_Watcher.Deleted += new FileSystemEventHandler(OnChanged);
m_Watcher.Renamed += new RenamedEventHandler(OnRenamed);
m_Watcher.EnableRaisingEvents = true;
///Initializing delegate that we have created to update UI control outside the current thread
addItemInList = new delAddItem(this.AddString);
}
并monitorFolder
在我的函数中调用
monitorFolder(draft);
monitorFolder(release);
monitorFolder(archive);