![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I'm using the FileSystemWatcher class to get notified when a file is created: myFileSystemWatcher.Created += new FileSystemEventHandler(myHandler); Sometimes (though rarely), myHandler executes fine. However, most of the time it appears to die on the first line of execution: private void myHandler(object source, FileSystemEventArgs e) { try { Thread.Sleep(4000); // Do more stuff } catch(Exception aException) { // This never get called } } If I set a breakpoint on the line: Thread.Sleep(4000); It takes a long time for VS2005 to break. However, when it does, everything looks fine (as far as parameters, registers, etc.). I don't know if I'm overflowing the stack somehow, or why it is dying. Does anybody have any ideas? Thanks, -- John |
#3
| |||
| |||
|
|
Umm.. What's creating the file(s)? I didn't look it up in the documentation, but from what you wrote, I gather this function will be called whenever a file (or any file?) is created (i.e. not updated or modified, just created from a deleted or non-existent file). I'm going to guess your file(s) aren't being created too often, and only when a file is created is your event handler being reached. i.e. the event handler isn't the problem. But honestly, I don't think you gave enough sample code or information to know that one way or the other. -Rob "John" wrote: I'm using the FileSystemWatcher class to get notified when a file is created: myFileSystemWatcher.Created += new FileSystemEventHandler(myHandler); Sometimes (though rarely), myHandler executes fine. However, most of the time it appears to die on the first line of execution: private void myHandler(object source, FileSystemEventArgs e) { try { Thread.Sleep(4000); // Do more stuff } catch(Exception aException) { // This never get called } } If I set a breakpoint on the line: Thread.Sleep(4000); It takes a long time for VS2005 to break. However, when it does, everything looks fine (as far as parameters, registers, etc.). I don't know if I'm overflowing the stack somehow, or why it is dying. Does anybody have any ideas? Thanks, -- John |
#4
| |||
| |||
|
|
Hey Rob, All of your assumptions are correct. I don't think the event handler is the problem either. I'm actually completely uncertain where to even begin to look though. I have no idea why the code would just all of the sudden die in that thread. I didn't write all of the code for this project, I'm just the guy that has to maintain it. Any other random ideas why a thread would all of the sudden just die? "RobertW" <RobertW (AT) discussions (DOT) microsoft.com> wrote in message news:7AC9113E-04F2-47A8-AC18-A1C84E7D301F (AT) microsoft (DOT) com... Umm.. What's creating the file(s)? I didn't look it up in the documentation, but from what you wrote, I gather this function will be called whenever a file (or any file?) is created (i.e. not updated or modified, just created from a deleted or non-existent file). I'm going to guess your file(s) aren't being created too often, and only when a file is created is your event handler being reached. i.e. the event handler isn't the problem. But honestly, I don't think you gave enough sample code or information to know that one way or the other. -Rob "John" wrote: I'm using the FileSystemWatcher class to get notified when a file is created: myFileSystemWatcher.Created += new FileSystemEventHandler(myHandler); Sometimes (though rarely), myHandler executes fine. However, most of the time it appears to die on the first line of execution: private void myHandler(object source, FileSystemEventArgs e) { try { Thread.Sleep(4000); // Do more stuff } catch(Exception aException) { // This never get called } } If I set a breakpoint on the line: Thread.Sleep(4000); It takes a long time for VS2005 to break. However, when it does, everything looks fine (as far as parameters, registers, etc.). I don't know if I'm overflowing the stack somehow, or why it is dying. Does anybody have any ideas? Thanks, -- John |
#5
| |||
| |||
|
|
Ok, Random thoughts I'm good with... Useful ? Eh.. From what I understand about threads, and I don't do a whole lot of multithreaded programming (the work I do wouldn't benefit that much from it, though I do it in some areas like background loading of data): -Event handling should happen in the main thread, and when the main thread exits, the program exits. -If you want a sub-thread or new-thread to handle an event, you catch the event in the main thread, then in the event handler, call a 'real event handler' in a new thread (i.e. create a new thread for that purpose), and return immediately so the flow of control returns normally to the main thread. So, when you say 'the thread dies' I'm not sure if you mean a sub-thread dies or the main program thread dies. If the whole program dies, then that's a bigger problem you may need to troubleshoot with a debugging tool to find what causes the main program to exit. This is not based on specific knowledge of threading in .net, but rather older threading models I've used. -Rob "John" wrote: Hey Rob, All of your assumptions are correct. I don't think the event handler is the problem either. I'm actually completely uncertain where to even begin to look though. I have no idea why the code would just all of the sudden die in that thread. I didn't write all of the code for this project, I'm just the guy that has to maintain it. Any other random ideas why a thread would all of the sudden just die? "RobertW" <RobertW (AT) discussions (DOT) microsoft.com> wrote in message news:7AC9113E-04F2-47A8-AC18-A1C84E7D301F (AT) microsoft (DOT) com... Umm.. What's creating the file(s)? I didn't look it up in the documentation, but from what you wrote, I gather this function will be called whenever a file (or any file?) is created (i.e. not updated or modified, just created from a deleted or non-existent file). I'm going to guess your file(s) aren't being created too often, and only when a file is created is your event handler being reached. i.e. the event handler isn't the problem. But honestly, I don't think you gave enough sample code or information to know that one way or the other. -Rob "John" wrote: I'm using the FileSystemWatcher class to get notified when a file is created: myFileSystemWatcher.Created += new FileSystemEventHandler(myHandler); Sometimes (though rarely), myHandler executes fine. However, most of the time it appears to die on the first line of execution: private void myHandler(object source, FileSystemEventArgs e) { try { Thread.Sleep(4000); // Do more stuff } catch(Exception aException) { // This never get called } } If I set a breakpoint on the line: Thread.Sleep(4000); It takes a long time for VS2005 to break. However, when it does, everything looks fine (as far as parameters, registers, etc.). I don't know if I'm overflowing the stack somehow, or why it is dying. Does anybody have any ideas? Thanks, -- John |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |