【发布时间】:2012-08-25 06:51:43
【问题描述】:
我有一个 Windows 应用程序,它使用 FileSystemWatcher 来监视文件的更改。可以添加多个文件位置,并为每个位置创建一个新的 FileSystemWatcher 实例,并将该位置添加到列表框中。有一个从列表框中删除位置的选项。删除位置时,我需要删除/处置 FileSystemWatcher 的特定实例。有什么办法可以做到这一点?提前致谢。
FileSystemWatcher fsw;
private void CreateFWInstance(string strLoc)
{
if (strLoc != string.Empty)
{
fsw = new FileSystemWatcher();
fsw.Changed += new FileSystemEventHandler(OnChanged);
fsw.Path = strLoc;
fsw.SynchronizingObject = this;
fsw.EnableRaisingEvents = true;
}
}
【问题讨论】:
标签: c# filesystemwatcher windows-applications