CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2009
    Posts
    5

    Unhappy can anybody pleeeeeeeeeease help me......

    Hi everybody!
    I am trying to suspend and resume a thread using two 'Menu' buttons 'Start' & 'Stop'. I have created the thread as below

    CWinThread *PWinThread;

    OnCreate()
    {
    int Code = 1;
    PWinThread = AfxBeginThread(ThreadFunction, &Code);
    }

    OnStart()
    {
    PWinThread->ResumeThread();
    }

    OnStop()
    {
    DWORD ExitCode;

    PWinThread->SuspendThread();

    ::GetExitCodeThread(PWinThread->m_hThread, &ExitCode);
    if(ExitCode == STILL_ACTIVE)
    ::MessageBox(0,"Thread","Is still Running",0);
    }

    When i click on 'Stop' button, I get the messagebox indicating that thread is still active.........can somebody trace it out please..............

  2. #2
    Join Date
    Feb 2009
    Posts
    5

    Re: can anybody pleeeeeeeeeease help me......

    Please dont skip if u know the answer.........

  3. #3
    Join Date
    Nov 2003
    Posts
    1,902

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: can anybody pleeeeeeeeeease help me......

    Looks like CodePlug already answered in the other post.

    You're getting the terminology between pausing and stopping messed up.

    Stopping generally means to end the thread operation. Pausing means to suspend the operation of the thread. In other words, it means to temporarily halt it, so it can be resumed later. A stopped thread cannot be resumed - it can only be restarted it.

    So now on to your code. When you suspend the thread and then use GetExitCodeThread to check the thread status, you get a STILL_ACTIVE because the thread is still active (it might be in a suspended state, but this is considered active because the thread hasn't exited or been terminated).

  5. #5
    Join Date
    Mar 2009
    Posts
    1

    Thumbs up Re: can anybody pleeeeeeeeeease help me......

    Hi,

    Well, you want to stop the thread whereas you are attempting to suspend it. Suspension of a thread will keep it still active (only suspend its execution till you resume it again).

    In your case you may want to conditionally let the thread complete it execution in the OnStop handler. This can be achieved using a condition processing logic within your thread routine.

    Hope it serves your need

    love-n-peace,
    ~shaan
    http://objects.blog.co.in/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured