Events&threads

  • Thread starter Thread starter joe
  • Start date Start date
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
 
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
 
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
 
Back
Top