【发布时间】:2011-08-15 20:52:30
【问题描述】:
我有一个应用程序正在使用 FileSystemWatcher 来监视文件夹中的文件更改。问题是当它捕捉到这些事件时,它需要对这些文档进行更改(更新链接),这当然会再次触发事件,从而使应用程序陷入循环。
所以我尝试了这个:
UnWireEvents(); //Turn off the events while updating the documents
ChangeAllLinks();
WireEvents(); //Turn the events back on
private void WireEvents()
{
_monitor.FileChanged += new EventHandler(_monitor_FileChanged);
}
private void UnWireEvents()
{
_monitor.FileChanged -= new EventHandler(_monitor_FileChanged);
}
但它似乎不起作用,应用程序仍然进入循环。那么为什么它不起作用,我需要做什么呢?
【问题讨论】:
标签: events c#-4.0 filesystemwatcher