Malcolm McCaffery
Malcolm McCaffery

Reputation: 2576

safely exit program Win32 C++ from detached std::thread

I have a simply utility that has GUI merely to provide progress and respond to mouse clicks for a button, in win main I've used std::thread and .detach to allow my worker thread to do the job without interrupting GUI. It works great, However I am wondering best method to safely end application (Note: I am Using Visual Studio 2013)

As far as I can tell there is no way to trigger an action on thread completion to exit the application , like .NET BackGroundWorker.

Upvotes: 1

Views: 250

Answers (1)

Gautam Jain
Gautam Jain

Reputation: 6849

You can hold the handle to the main window (HWND) in your thread and post WM_QUIT message from your thread to the main UI thread.

You can use PostMessage or PostThreadMessage functions.

Upvotes: 2

Related Questions