P
Peter Duniho
Alberto said:I believe that you are wrong. Unless you have written a multithreaded
program, no event can occur until all previously executing code has
finished and execution has returned into the piece of code that fires
the event, so no method can be interrupted by the event.
Unless, of course, the event is raised by some method called by the
method that's executing.
It's possible that this is what the OP is running into, giving him a
false impression of how events work.
This can only happen if your code is multithreaded. In this case you
will have written code somewhere to start the separate thread where code
is executing at the same time that an event happens. If you want to stop
the separate thread from your event code, you can execute a
thread.Interrupt or thread.Abort on the thread that you previously started.
Noting, of course, that aborting a thread is generally a very poor way
to manage thread execution. Thread.Interrupt is somewhat better, but
only if you've specifically designed the thread to handle the generated
exception correctly. It's not something I'd want to just stick into an
existing thread without fixing the design to take it into account.
That said, I agree that _something_ along those lines is going to be
needed to implement the behavior asked for. But generally, there would
be a more explicit inter-thread communication (like a volatile flag
telling the thread to exit, which it can check periodically), IMHO.
Pete