I'm using C# in Visual Studio 2010 with the framework 4.0.
In my project, in two different forms, there are two FileSystemWatcher
s with the property EnableRaisingEvent
set to false
. If I close Visual Studio, when I reopen it I get in both FileSystemWatcher
the property EnableRaisingEvent
set to true
.
In both my forms in the designer file there is the following code:
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);
}
The property EnableRaisingEvent
is not set, but the default is false
.
Any idea why I get this strange behaviour?
edit
I followed the Virtlink's suggestion, adding the following line of code:
this.fileSystemWatcher1.EnableRaisingEvents = false;
It seemed to solve my problem, but after a few days (and some opening, closing and rebuilding of the project, but without modifying the fileSystemWatcher1
) I found:
in the designer, in the properties of the
fileSystemWatcher1
,EnableRaisingEvents
was set back totrue
in the code, the line previously added was missing
I tried moving to Visual Studio 2012 (still framework 4.0) and the workaround fixed the problem for some more days. Then I got the same situation as in VS10.
Any other idea?