Sending messages...

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
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
A

Atmapuri

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
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 

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

Similar Threads

Threading question! 7
Synchronize or invoke? 1
Unmanaged code interop! 1
Multithreaded GC! 42
beginners question about UI threading 10
Creating forms! 2
Design time serialization! 1
Records passed to unmanaged code! 2

Top