I’ve noticed that AutoResetEvent completely freezes the message loop (sometimes) when in the middle of a WaitOne() call, effectively even blocking the signal message.
IE:
- (UI) New thread spawned
- (UI) Code calls WaitOne(); timeout: 10s
- (T2) Thread opens device, calls Set()
- (UI) WaitOne blocks message loop
- (UI) WaitOne timeout elapsed, code execution continues
- (UI) Main window receives signal and continues (but WaitOne failed)
Any ideas?
EDIT: added UI/T2’s to specify threads. Also, I’m trying to turn a 3rd party library to synchronous. Opening devices involves an Open() call that in turn spawns an OpenOK or OpenFailed event, I’m trying to make a bool Open() call that returns true/false depending on which event was spawned.
You can’t “block a signal” from being sent, you can only prevent the other thread from getting to the point of setting the event. Wait handles do not require a message pump at all.
The only thing I can think of may be that the COM object in question is tied to the UI thread. Accessing the COM object may be attempting to invoke back from T2 to the UI thread which is waiting for T2 to do something (deadlock). To see if this is indeed the problem make sure you are not creating or accessing the COM object on the UI thread.