I see. To use manual reset, you need to call
m_KeyPressedEvent.Reset
in the blocked thread right after return from
m_KeyPressedEvent.Wait
. Just do
m_KeyPressedEvent.Wait();
m_KeyPressedEvent.Reset();
Alternatively, use auto-reset.
[EDIT]
Remove that
wait(true)
, immediately, never do it again, ever!
This is not a spin wait! Never use spin wait!
EventWaitHandle.Wait
is blocking. The thread is switched off by OS and put to a wait state using zero CPU time. In other words, OS never schedule this thread for executions until it is awaken by
Set
.
—SA