To reporoduce, run the code.
Observed: Form is shown
Expected: message box should displayed.
How to fix ?
Andrus.
using System;
using System.Windows.Forms;
using System.IO;
class main {
[STAThreadAttribute()]
public static void Main() {
File.Delete("c:\\test");
using (FileSystemWatcher watch = new FileSystemWatcher()) {
watch.Path = "c:\\";
watch.Filter = "test";
watch.Created += new FileSystemEventHandler(OnChanged);
watch.Deleted += new FileSystemEventHandler(OnChanged);
watch.Changed += new FileSystemEventHandler(OnChanged);
watch.EnableRaisingEvents = true;
}
FileStream oFs = new FileStream("c:\\test", FileMode.CreateNew,
FileAccess.ReadWrite);
StreamWriter oWriter = new StreamWriter(oFs);
oWriter.Flush();
oWriter.Close();
oFs.Close();
File.Delete("c:\\test");
Application.Run(new Form());
}
static void OnChanged(object sender, FileSystemEventArgs e) {
MessageBox.Show(e.FullPath + e.ChangeType.ToString());
}
}