Sending messages...

  • Thread starter Thread starter Atmapuri
  • Start date Start date
A

Atmapuri

Hi!

I have a thread and would like to send a Windows Message
to the component that encapsulates the thread, so that the
event specified to react on that message would be raised.

I know how to do that in C++, but I am a bit lost with CLR.

Thanks!
Atmapuri
 
Atmapuri,

Have you taken a look at the Invoke method on the Control class? It
will do what you want, you pass it a delegate and arguments to be passed to
the delegate, and it will make the call to the delegate on the thread that
created the control.
 
Hi!
Have you taken a look at the Invoke method on the Control class? It
will do what you want, you pass it a delegate and arguments to be passed
to the delegate, and it will make the call to the delegate on the thread
that created the control.

The help file says:
"If the control's handle does not exist yet, this method searches up the
control's parent chain
If no appropriate handle can be found, the Invoke method will throw an
exception."

My component does not have a parent. In C++ I would call:

CreateWindowEx(WS_EX_TOOLWINDOW,...

To get the handle.

Thanks!
Atmapuri
 
Atmapuri,

Well, if that component is expecting windows messages, then it means
that it is pumping for them on a particular thread. If you have a thread
id, then you can send a message to that thread queue calliong the
PostThreadMessage API function through P/Invoke. If you have a handle to a
window that is owned by that thread, then you can call SendMessage through
the P/Invoke layer.
 
Back
Top