Events&threads

J

joe

Hi,

I have a dedicated worker thread for receiving bytes from
the serial port.
Upon receiving it fires an event RxData.

The main application thread has an event handler for
RxData. When I receive data from the port I want to create
a button and put it on the form. But I get exception:

"Controls created on one thread cannot be parented to a
control on a different thread"

But the event handler is in the main thread which is also
the GUI thread!
Does that mean that even if the event handler is in one
thread, it is considered by .NET as being in the thread
which fires the event?

Thank you
Joe
 
S

Sunil TG

As you might think, the event handler thread will not be
the application main thread.
What you can do to solve the issue is, put a hidden button
in your main form, and from the event handler, make it
visible.

HTH
Sunil
 
R

Rajesh.V

Sankalp,

Can you tell me which book is that.
tx
joe said:
Thanks for the help. I actually bought Chriss Sells's book
and it has this very example and explaining how to do deal
with UI from different threads
 

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