Parenting troubles

M

Mike Hildner

I have an MDI parent as my main form. Created a class library with a
component. This component waits for a UDP message, my plan was to pop up a
window showing the message when it arrives. The component raises an event in
response to the message - the MDI parent handles this event.

When this happens I get the following exception:
"Controls created on one thread cannot be parented to a control on a
different thread"

I am trying to pop up a MDI child form in the event handler. The component
starts a thread in the constructor - since there's no Sub Main in my
component, I launched this thread that calls a sub which has a never ending
loop to wait for incoming messages.

I imagine what I'm trying to do is possible, and that I just don't
understand enough to get it going. Can anyone suggest the proper way to
accomplish what I'd like to do?

Thanks,
Mike
 
H

Herfried K. Wagner [MVP]

* "Mike Hildner said:
I have an MDI parent as my main form. Created a class library with a
component. This component waits for a UDP message, my plan was to pop up a
window showing the message when it arrives. The component raises an event in
response to the message - the MDI parent handles this event.

When this happens I get the following exception:
"Controls created on one thread cannot be parented to a control on a
different thread"

I am trying to pop up a MDI child form in the event handler. The component
starts a thread in the constructor - since there's no Sub Main in my
component, I launched this thread that calls a sub which has a never ending
loop to wait for incoming messages.

Create the control in the main GUI thread. You can do this by defining
a public method in one of the form classes and then using
'Control.Invoke' on this method from within the thread.
 

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