By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,677 Members | 1,877 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,677 IT Pros & Developers. It's quick & easy.

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

P: n/a
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?

Nov 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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

On Fri, 22 Jul 2005 18:30:22 +0200, Michael Gorbach <mg******@gmail.com>
wrote:
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?

Nov 17 '05 #2

P: n/a
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

On Fri, 22 Jul 2005 18:30:22 +0200, Michael Gorbach <mg******@gmail.com>
wrote:
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?

Nov 17 '05 #3

P: n/a
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.

Nov 17 '05 #4

P: n/a
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.

Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.