我在Visual Studio 2010中使用框架4.0中的C#。每次打開Visual Studio時,FileSystemWatcher EnableRaisingEvent都會更改
在我的項目中,有兩種不同的形式,有兩個FileSystemWatcher
s,屬性EnableRaisingEvent
設置爲false
。如果我關閉Visual Studio,當我重新打開它時,我同時獲得FileSystemWatcher
屬性EnableRaisingEvent
設置爲true
。
在我在設計文件中這兩種形式有以下代碼:
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一樣的情況。
還有其他想法嗎?
您能否確認,您添加了Virtlink的建議'this.fileSystemWatcher1.EnableRaisingEvents = false;'在Form.cs文件的構造函數中? – 2013-03-18 03:32:29
@jacobaloysious我做了,似乎解決了這個問題!謝謝 – 888 2013-03-22 10:02:04