|
-
February 6th, 2009, 04:00 AM
#1
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..............
-
February 6th, 2009, 08:58 AM
#2
Re: Thread doesn't suspend!!!
Suspended or not, it's still active until the thread returns from its thread function.
gg
-
February 9th, 2009, 12:42 AM
#3
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............
-
February 9th, 2009, 07:58 AM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|