Re: how to end a thread from the main thread

Tech-Archive recommends: Fix windows errors by optimizing your registry



That would be silly. If I were doing that, I'd wait on the thread handle, because it is
more efficient (Sleep(10) will essentially push CPU utlization towards 100%). It has the
same set of problems, because it blocks the message pump.
joe

On Fri, 23 Dec 2005 11:16:44 +0100, Michael Nielsen <mnielsen@xxxxxxx> wrote:

>Joseph M. Newcomer wrote:
>> The trick goes like this...
>>
>> Suppose for this example I have a boolean, ThreadRunning, on behalf of a view. Also a
>> boolean called closing. Both are initialized to false, and ThreadRunning is set to TRUE
>> when the thread starts
>>
>> void CMyView::OnClose()
>> {
>> if(ThreadRunning)
>> {
>> ... initiate thread shutdown
>> closing = TRUE;
>> }
>> CView::OnClose();
>> }
>>
>>
>> LRESULT CMyView::OnThreadFinished(WPARAM, LPARAM)
>> {
>> ThreadRunning = FALSE;
>> if(closing)
>> PostMessage(WM_CLOSE);
>> return 0;
>> }
>>
>
>Don't you need a variable isClosed and set it true as the last thing the
>thread does so the application can wait for it
>(while(!isClosed)Sleep(10);) to be closed before exiting?
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: Save text from CList into file
    ... Joseph M. Newcomer ha escrito: ... Why NULL for the default extension when you clearly meant _T? ... See my articles on using FormatMessage in MFC on my MVP Tips site ...
    (microsoft.public.vc.mfc)
  • Re: .Saved property doesnt change
    ... In article, Joseph M. Newcomer wrote: ... // OMITTED: report error here ... Joseph M. Newcomer ... MVP Tips: http://www.flounder.com/mvp_tips.htm ...
    (microsoft.public.office.developer.vba)
  • Re: SDK and VC6.0
    ... "Joseph M. Newcomer" wrote: ... > us to give up VS6. ... > MVP Tips: http://www.flounder.com/mvp_tips.htm ...
    (microsoft.public.vc.mfc)
  • Re: Spam humor
    ... "Joseph M. Newcomer" wrote in message ... Title: Brain Damage Lawyer ... Joseph M. Newcomer ... MVP Tips: http://www.flounder.com/mvp_tips.htm ...
    (microsoft.public.vc.mfc)
  • Re: error R6031
    ... "Joseph M. Newcomer" wrote: ... The fact that you have what appears to be a statically-linked CRT in a DLL (I'd suggest ...
    (microsoft.public.vc.mfc)