I have a problem with an event handler that opens a form. The form appears, but it freezes immediately. This doesn't happen for all events, such as those that my other forms create (like menu items or button clicks), but it does happen for the system-based events like FileSystemWatcher and NetworkAddressChanged.
Here's what I did to demonstrate the problem:
I've made an event handler for the FileSystemWatcher.Created event, so that it is fired whenever someone creates a file in the monitored directory:
FileSystemWatcher watcher = new FileSystemWatcher("c:\\");
watcher.Created += new FileSystemEventHandler(watcher_Created);
watcher.EnableRaisingEvents = true;
In that handler, I create an instance of a very simple form that has no code other than the designer stuff:
static void watcher_Created(Object sender, FileSystemEventArgs e) {
Form test = new Form1();
test.Show();
}
When I run my program, I go into c:\ and create a new file, causing the event to fire. The form pops up, but it is completely frozen. You can't close it, and the button isn't visible. The cursor is an hourglass. When I run this code in my real app, it's clear that the program is still functioning in the background because other forms still respond. However, the form that was opened by the event is completely unresponsive. Does anyone know why this might happen? I have a very simple test solution that I can link to if necessary.
Here's what I did to demonstrate the problem:
I've made an event handler for the FileSystemWatcher.Created event, so that it is fired whenever someone creates a file in the monitored directory:
FileSystemWatcher watcher = new FileSystemWatcher("c:\\");
watcher.Created += new FileSystemEventHandler(watcher_Created);
watcher.EnableRaisingEvents = true;
In that handler, I create an instance of a very simple form that has no code other than the designer stuff:
static void watcher_Created(Object sender, FileSystemEventArgs e) {
Form test = new Form1();
test.Show();
}
When I run my program, I go into c:\ and create a new file, causing the event to fire. The form pops up, but it is completely frozen. You can't close it, and the button isn't visible. The cursor is an hourglass. When I run this code in my real app, it's clear that the program is still functioning in the background because other forms still respond. However, the form that was opened by the event is completely unresponsive. Does anyone know why this might happen? I have a very simple test solution that I can link to if necessary.