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

    Thread doesn't suspend!!!

    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
    Nov 2003
    Posts
    1,902

    Re: Thread doesn't suspend!!!

    Suspended or not, it's still active until the thread returns from its thread function.

    gg

  3. #3
    Join Date
    Feb 2009
    Posts
    5

    Re: Thread doesn't suspend!!!

    But this nature of a working thread doesn't serve any purpose............actually, in my application a thread is continuously writing data to a .txt file and the main application is reading that data for plotting it on the monitor using a software timer.........now suppose if i want to suspend this whole process then i have to kill the timer for stopping the main application job (which is happening) and anyhow suspend the thread (this is creating problem).............then how can i solve it alternatively............

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

    Re: Thread doesn't suspend!!!

    You don't use SuspendThread() as means for synchronization (as the documentation states). Use a synchronization object instead - like a manual reset Event. The main loop of the thread would then uses a wait-function to proceed only if the Event is in a signaled state.
    http://msdn.microsoft.com/en-us/libr...53(VS.85).aspx

    gg

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