It seems that the workflow is not able to close properly after closing your application, as the process ends before it exits. The operating system, as a rule, is pretty well versed in resources by itself, so this may not be a problem. However, it is probably best if you wait for this thread to exit before allowing the application to close. Although it sounds like it will lead to a delay of 4 seconds when you turn off your application.
If this is unacceptable, you will need to add a mechanism to the thread to get the shutdown event from the main application thread. For example, if you replace the workflows with "sleep", with the WaitForSingleObject event:
DWORD res = WaitForSingleObject( shutdownEvent, 4000); // timeout if(res == WAIT_OBJECT_0) { // received the shutdownEvent, exit return 0; } // The delay has elapsed, continue with rest of thread. . . .
Then, when you stop in your main thread, set the event, and then wait for the thread to exit, it should exit almost immediately:
SetEvent(this->shutdownEvent); WaitForSingleObject(pThread->m_hThread, INFINITE); // pThread is returned from AfxBeginThread
source share