473,321 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

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

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
4 6433
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jon | last post by:
I am writing an MDI app that uses a document manager class to keep track of opened child windows. I want the user to be able to close a child window, but then re-open the window from the "Window"...
0
by: Michael Gorbach | last post by:
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...
10
by: Bande | last post by:
There is a program in VB , in which, there is a Form_QueryUnload( Cancel as Integer, UnloadMode as Integer) which would be called when the form is being closed. The UnloadMode is used to find...
7
by: Xero | last post by:
How do you detect whether a form has been closed or not? Thanks. -- Xero http://www.chezjeff.net My personal web portal
2
by: Geoff Jones | last post by:
Hiya Supposing a form has been created as follows: Dim form1 As New Form How can I check to see if the form has been closed i.e. by clicking on the cross in the top right of the form. ...
28
by: Gaby | last post by:
Hi guys, I have this ASP code that is a little long to post so but you can download it off of http://whatthedeuce.net/Form.asp I cant find out what my error is. I know it is not in my Access...
2
by: Mike Baugh | last post by:
I am using visual studio 2005 to develop a form using c# I have 3 datagrids on one form. I can set the row color based on a certain value in a column. However this color applies to all 3...
11
by: Zytan | last post by:
I have created a new form from the main form. When I close the main form with the 'x' close button, its Form.FormClosed event is run, but not the dialog's. Is this normal? It is ok /...
9
by: Anil Gupte | last post by:
I have a MDI Parent Child set of forms FormContainer --MDIParent FormStart --MDIChild FormMain-->MDIChild FormSliceInfo-->MDIChild I use the following in the beginning of FomrContainer ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.