Thread-Safe Forms (MDI Childs)

F

Frank Uray

Hi all

Got a problem with thread-safety:
I have a frm_main witch is a mdi-container.
I am trying to show mdi-child form from another
thread and get of corse an exeption:
"Controls created on one thread cannot be parented to a
control on a different thread."
How do I do this in the right way??

Thanks for any help!

Frank Uray
 
H

Herfried K. Wagner [MVP]

Frank Uray said:
Got a problem with thread-safety:
I have a frm_main witch is a mdi-container.
I am trying to show mdi-child form from another
thread and get of corse an exeption:
"Controls created on one thread cannot be parented to a
control on a different thread."
How do I do this in the right way??

You must show the forms in the main UI thread. You can access the
controls/forms with invoking:

<http://www.devx.com/dotnet/Article/11358>
 
F

Frank Uray

Thanks for the answer!

I dont need to access controls on the main form,
i just like to show the form as mdi-child.

On the click event in the main form i start
a thread witch is then showing a form as mdi-child,
this would be the goal...

Any ideas?

Best regards
Frank
 
H

Herfried K. Wagner [MVP]

Frank Uray said:
I dont need to access controls on the main form,
i just like to show the form as mdi-child.

On the click event in the main form i start
a thread witch is then showing a form as mdi-child,
this would be the goal...

Then you must tell the main GUI thread to create the MDI form. You
cannot create the form from within the 2nd thread. I remember I posted
a link that describes how to do that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top