Reputation:
I am fixing a GUI application programmed with MFC. To run a communication stack a new thread is created. On some events I want to stop this but I know that only in the worker thread and I cannot get the correct behaviour from stopping the worker thread from itself. So I need to send a message to the main thread and tell it to stop the worker thread so that the main thread can then take the correct action.
I am unsure how to do this. I have looked at the SendMessage function in CWnd but it does not take threadid as an argument and I dont get what I need to include to use http://msdn.microsoft.com/en-us/library/windows/desktop/ms644944(v=vs.85).aspx.
Upvotes: 0
Views: 960
Reputation: 10415
Actually, the only safe way to do anything to a worker thread is from within the worker thread itself. It should probably be structured as a while(bRun) loop so it runs until the program is shutting down. Whatever you are trying to do (stop and start) should be handled by code in the while loop.
Upvotes: 0