Need help ... how to find if form is closed?

  • Thread starter Thread starter Michael Gorbach
  • Start date Start date
M

Michael Gorbach

Iv got a little bit of a threading problem.
Iv got a form which handles events fired by an object running on
another thread (the event handlers are executed on a thread differnet
from the form's gui thread). Im using BeginInvoke to call methods on
the form that manipulate its GUI elements, as is reuqired. The problem
is this: When that particular form is closed and the object is still
running, the events still fire and get caught by the event handlers.
The BeginInvoke call fails with an InvalidOperationException (something
about the window handle not being created). Although i can catch this
excpetion and ignore it, doing this would slow down my prgoram alot and
would break the guideline of not having exceptions thrown during normal
program execution (it is normal for this form to be closed, as it is a
helper form). How do i check if the form is open and has a window
associated with it?
 
Hello,

I would recommend you to handle the Form's Closed event. Your handler
simply detaches every registered event handler which gets executed on your
form.

greets
 
ah ... great idea. I dont know why i didnt think of that.
For some reason the first thing comming into my head was to check in
the method that calls the begininvokes.
 
Back
Top