日期:2014-05-17 浏览次数:21744 次
foreach (ListViewItem i in this.listView.Items)另外希望通过按钮二停止对ListView列出的文件监视。
{
this.fileSystemWatcher = new FileSystemWatcher();
this.fileSystemWatcher.Path = i.SubItems[2].Text;
if (i.Group == G1)
{
this.fileSystemWatcher.Filter = i.SubItems[0].Text;
this.fileSystemWatcher.Changed += new FileSystemEventHandler(watcher_Changed);
}
else
{
this.fileSystemWatcher.Created += new FileSystemEventHandler(watcher_Created);
this.fileSystemWatcher.Deleted += new FileSystemEventHandler(watcher_Deleted);
this.fileSystemWatcher.Renamed += new RenamedEventHandler(watcher_Renamed);
}
this.fileSystemWatcher.EnableRaisingEvents = true;
}
{现在出现的问题是按钮二不能清除之前加载的更新,也不能停止对文件的监视,按钮一点几次之后就会发生多次对同一文件监视事件发生。按钮二里面我的代码应该怎么写呢?,达到效果就是停止并清除所有监视
this.fileSystemWatcher.EnableRaisingEvents = false;
}
List<FileSystemWatcher> all = new List<FileSystemWatcher>();
private void button1_Click(object sender, EventArgs e)
{
foreach (ListViewItem i in this.listView.Items)
{
this.fileSystemWatcher = new FileSystemWatcher();
all.Add(fileSystemWatcher);
this.fileSystemWatcher.Path = i.SubItems[2].Text;
if (i.Group == G1)
{
this.fileSystemWatcher.Filter = i.SubItems[0].Text;
this.fileSystemWatcher.Changed&n