Thread Safe Error / Multi Thread ?

rogern

New member
Joined
Nov 23, 2006
Messages
2
Programming Experience
Beginner
Yes Im essentially a beginner, so all the usual appologies !

I simply want to show a child form from a parent from, and if the parent form is clicked, close the child form. But I appear to be running into all sorts of thread saftey warning message's. Is there a simple way to achieve the above or do I have to inwardly digest all this stuff about cross thread safety and backgound worker processes ?
 
You should NOT use the LostFocus event of the child form at all, but rather the Deactivate event. Also, just because the child is deactivated doesn't mean that the parent is activated. It could be because a completely unrelated application was activated. It's also possible to activate the parent via Alt+Tab, which involves no clicks at all, so you need to decide whether you really do mean when the parent is clicked or actually when the parent is activated.

What you should do is handle the Activated (or Click if appropriate) event of the parent and then close the child from there, which ensures that it isn't just that some other application has become active.

Also, that is a very unusual way to handle forms. It may be legitimate but it may be that you'd be better off displaying the child form with ShowDialog instead of Show.
 
Last edited:
Back
Top