AJ De Guzman
AJ De Guzman

Reputation: 3

Disabling control variable while worker thread is finishing MFC

I am working on a dialog-based MFC Application using Visual Studio 2015. Basically my problem is that I have a button that will start a worker thread after the user has chosen the necessary inputs (.csv files that will be parsed and put into different vectors). To avoid complications, I decided that the user will not be able to press this button or the input buttons until after the calculation done by the worker thread has finished. I tried the WaitforSingleObject options but defeats the purpose of keeping the main thread or the MFC Application running while waiting for the worker thread to finish. Is there any other workaround around this problem? I appreciate any help.

Upvotes: 0

Views: 281

Answers (2)

Neil
Neil

Reputation: 55392

Your worker thread could post a completion message back to your UI thread. Your UI thread wouldn't need a special message loop in that case, instead your window procedure would then reenable the buttons when it receives that message.

Upvotes: 4

Steve
Steve

Reputation: 1810

You could use the MsgWaitForMultipleObjects function: https://msdn.microsoft.com/en-us/library/windows/desktop/ms684242(v=vs.85).aspx

ATL uses it in AtlWaitWithMessageLoop(https://msdn.microsoft.com/en-us/library/26hwk2bx.aspx).

Upvotes: -2

Related Questions