Every time I open Visual Studio, changes to the FileSystemWatcher EnableRaisingEvent change

I am using C # in Visual Studio 2010 with framework 4.0.

In my project in two different forms, there are two FileSystemWatcherwith the property EnableRaisingEventset to false. If I close Visual Studio when I open it again, I get FileSystemWatchera EnableRaisingEventvalue in the property true.

In both of my forms, the constructor file has 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 is EnableRaisingEventnot set, but it is by default false.

Any idea why I get this weird behavior?

change

I followed the Virtlink suggestion by adding the following line of code:

this.fileSystemWatcher1.EnableRaisingEvents = false;

, , ( , , fileSystemWatcher1) :

  • , fileSystemWatcher1, EnableRaisingEvents true

  • , ​​

Visual Studio 2012 ( Framework 4.0), . , VS10.

?

+5
3

Visual Studio 2012, Visual Studio. , True , .

, FileSystemWatcher.

, InitializeComponent:

this.fileSystemWatcher1.EnableRaisingEvents = false;

, . , InitializeComponent, , InitializeComponent - . - InitializeComponent .

InitializeComponent();
this.fileSystemWatcher1.EnableRaisingEvents = false;

, EnableRaisingEvents, , . , .

+2

, , . , # Visual Studio , , - . BeforeBuild .csproj, .

.Designer.cs, .resx, ​​ , Visual Studio, , , .resx. EnableRaisingEvents false , Visual Studio .

, , .

EDIT:

, , , Visual Studio : Visual Studio BeforeBuild?

+1

Virtlink , :

  public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.fileSystemWatcher1.EnableRaisingEvents = false;
        }
    }    

, , () designer.cs

. .

.Designer.cs( .Designer.vb Visual Basic) , , ; . , :

  • IDE , ( , , , , , ).
  • IDE . , .designer file, , . ( ), , IDE ( ). - , IDE .designer . , IDE , , , , .
+1

All Articles