-
February 26th, 2009, 11:50 PM
#1
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..............
-
February 26th, 2009, 11:52 PM
#2
Re: can anybody pleeeeeeeeeease help me......
Please dont skip if u know the answer.........
-
February 26th, 2009, 11:57 PM
#3
Re: can anybody pleeeeeeeeeease help me......
-
March 1st, 2009, 06:07 PM
#4
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).
-
March 15th, 2009, 11:14 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|