Waiting for Messages in Managed Code

This is related to the previous question.

In a managed world:

  • How can I check if the current thread has messages in the message queue?
  • How do I yield to the OS and wait for a message on the current thread (like GetMessage or WaitMessage)?

I'm looking for non-PInvoke managed equivalents.

+1


source to share


2 answers


You can use the AddMessageFilter function .



I don't think there is a blocking way to do this without P / Invoke, as it is not .NET intent.

0


source


You can override WndProc and then fire your own event when called. This will of course not block. If you want to block until the message, you can use the method on another thread that is waiting for a sync object and have the WndProc signal of that object.



+3


source







All Articles