private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.fileSystemWatcher1 = new System.IO.FileSystemWatcher();
((System.ComponentModel.ISupportInitialize)(this.fileSystemWatcher1)).BeginInit();
this.SuspendLayout();
this.fileSystemWatcher1.Filter = "my_filter";
this.fileSystemWatcher1.NotifyFilter = System.IO.NotifyFilters.LastWrite;
this.fileSystemWatcher1.SynchronizingObject = this;
this.fileSystemWatcher1.Changed += new System.IO.FileSystemEventHandler(this.fileSystemWatcher1_Changed);
}
属性EnableRaisingEvent
未设置,但默认值为false
。
有任何想法为什么会出现这种奇怪的行为?
编辑
我按照Virtlink的建议添加了以下代码行:
this.fileSystemWatcher1.EnableRaisingEvents = false;
看起来解决了我的问题,但几天后(并且打开、关闭和重建项目,但没有修改fileSystemWatcher1
)我发现:
在设计器中,在
fileSystemWatcher1
的属性中,EnableRaisingEvents
被设置回true
在代码中,先前添加的行消失了
我尝试转移到Visual Studio 2012(仍然是框架4.0),解决方法可以再工作几天。然后我遇到了与VS10相同的情况。
还有其他想法吗?