Is there any API t开发者_开发技巧o send message to a thread? Basically I have only threadId available and I want to send a custom message to that thread.
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.
you can use QueueUserAPC if the target thread is alertable
精彩评论