Launch Message Loop while Waiting for WaitHandle

Is there a way to handle all Windows messages while the UI thread is waiting in WaitHandle or another threading primitive?

I understand that this can create very dirty reconnecting issues; I still want to do this.

EDIT : The wait occurs in the middle of a complex function that must be run in a user interface thread. Therefore, moving the wait to the background thread is not an option. (Dividing the function into two parts would create a complex and incomprehensible mess)

+3
source share
4 answers

"----" , ( Invoke/BeginInvoke ).

, UI, unit test. , , .

+4

( - ) ?

, .

EDIT: - , . , . - .

, UI- , .

+3

#, Win32 MsgWaitFor...() . , , , . , GetMessage(), TranslateMessage() DispatchMessage() , .

+2

.

However, at the same time, you can always call Application.DoEvents to process the message-message at any time, including while waiting "on the handle, (wait time only, do events, wait with a timeout, etc., until you get "through" waithandle).

+2
source

Source: https://habr.com/ru/post/1709711/


All Articles