Używam języka C# w programie Visual Studio 2010 ze strukturą 4.0.Za każdym razem, gdy otwieram program Visual Studio, zmiany w pliku FileSystemWatcher EnableRaisingEvent
W moim projekcie, w dwóch różnych formach, są dwa FileSystemWatcher
s z właściwością EnableRaisingEvent
ustawioną na false
. Jeśli zamknę Visual Studio, po ponownym otwarciu otrzymam zarówno FileSystemWatcher
właściwość EnableRaisingEvent
ustawioną na true
.
W obu moich formularzy w pliku projektanta nie jest następujący kod:
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);
}
Obiekt EnableRaisingEvent
nie jest ustawiona, ale domyślnie jest false
.
Każdy pomysł, dlaczego dostaję to dziwne zachowanie?
edit
Poszedłem za sugestię Virtlink, dodając następujący wiersz kodu:
this.fileSystemWatcher1.EnableRaisingEvents = false;
Wydawało się rozwiązać mój problem, ale po kilku dniach (i niektórych otwierania, zamykania i przebudowa projektu, ale bez modyfikacji fileSystemWatcher1
) znalazłem:
w projektancie W właściwościach
fileSystemWatcher1
,EnableRaisingEvents
został cofnięty dotrue
w kodzie, linia uprzednio dodano brakujące
Próbowałem przeprowadzce do Visual Studio 2012 (jeszcze Framework 4.0) i obejście naprawiło problem na kilka kolejnych dni. Wtedy dostałem taką samą sytuację jak w VS10.
Każdy inny pomysł?
Czy możesz potwierdzić, dodałeś sugestię Virtlink "this.fileSystemWatcher1.EnableRaisingEvents = false; ' w konstruktorze pliku Form.cs? –
@jacobaloysious zrobiłem, i wydaje się, że to naprawić problem! Dziękuję też. – 888