Why does Control.Invoke () call PostMessage () instead of SendMessage ()?

Control.Invoke()calls PostMessage()and then waits until the user interface thread completes processing the message. So why doesn't it call SendMessage()instead (which by default waits until the user interface thread completes processing the message).

+4
source share
1 answer

Control.Invoke () is a dangerous method, many .NET programmers lock their program with it. Because of this, it should be avoided very much. Simple everyday operations, such as closing a window, become dangerous. You want to wait until the worker thread can call more, because nothing good happens when the thread continues to work, but the user interface does not work. This way you stream the stream using, say, AutoResetEvent and wait for it to complete.

, Invoke() . , Invoke(), , . " ", , . , , , Invoke .

, Invoke() , . , SendMessage(). , , . SendMessage, , , .

, Microsoft , PostMessage. , PostMessage, , . Invoke over BeginInvoke, ManualResetEvent , , .

- , , , , . , , , SendMessage , .

+4

All Articles