Is there any API to send message to a thread? Basically I have only threadId available and I want to send a custom message to that thread.
A:
If you use .NET, maybe this is udeful: http://www.codeproject.com/KB/threads/threadlib.aspx
Konamiman
2009-11-24 09:54:25
I forget to add C++ tag.
Alien01
2009-11-24 09:58:22
+4
A:
PostThreadMessage. Not very reliable though.
See The Old New Thing blog here and here for details on why. Basically modal message loops make a mess of the whole idea. Since a message posted to a thread has no window handle, calling DispatchMessage will throw the message away. Any modal loop you run - directly or indirectly - will call DispatchMessage, so a good proportion of the time this strategy will fail and your message will disappear into the ether.
Bob Moore
2009-11-24 10:19:15
Most important sentence from those two articles: "If you need to communicate reliably with a thread that also displays UI, then create a hidden window and send or post messages to that window."
Thomas
2009-11-24 10:30:49
Of course, if _all you have is a ThreadId_, that suggestion won't work either.
MSalters
2009-11-26 15:01:47