Re: problems in pausing and resumig threads

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Also there is one other thing that i would like to mention......the code in
procedure method has a infinite loop.....so what exactly i want is if too
much CPU is uitilized then user should be able to pause the thread and then
if he wishes to resume the thread, he can resume it from the same state....is
it possible to do so with events??

kunal

"Doug Harrison [MVP]" wrote:

On Sun, 25 Feb 2007 18:03:00 -0800, kunal s patel
<kunalspatel@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

Hi all,
I having problems in pausing and resuming the threads. Here is the relevant
piece of code

#include "simulation.h"

Class Cmaingui
{
pthread = AfxBeginThread(RunSim,this); //main application where i start
the
thread
}

See the following for some information on using MFC threads:

http://members.cox.net/doug_web/threads.htm

UINT RunSim(LPVOID WndPtr)
{
simulation sim;
sim.procedure();
return 0;
}

simulation
{
void procedure()
{
//some exection code
}

};

Now in Cmaingui if somebody presses pause, then i execute the following code

pthread -> SuspendThread();

So basically what i want to do is whenever a user presses pause, the
execution in procedure should stop immediately. But when i execute this code,
thread doesn't stop execution and hence procedure doesnt stop execution. Can
anyone please suggest me what is wrong in my code and how should i go about it

Except for resuming a thread that was started suspended, ResumeThread has
no use, because SuspendThread should not even exist, and given that it does
exist, it should not be used. The page I linked to talks about asking a
thread to exit and waiting for it to do so, and the principle is the same
for asking a thread to pause. The only difference is that you will have to
use an event or some other mechanism to communicate the paused state
instead of waiting on the thread handle to become signaled.

--
Doug Harrison
Visual C++ MVP

.



Relevant Pages

  • Re: problems in pausing and resumig threads
    ... SuspendThread should not be used to actually suspend a thread......and i ... Now in Cmaingui if somebody presses pause, then i execute the following code ... thread doesn't stop execution and hence procedure doesnt stop execution. ... instead of waiting on the thread handle to become signaled. ...
    (microsoft.public.vc.mfc)
  • Re: problems in pausing and resumig threads
    ... I having problems in pausing and resuming the threads. ... Class Cmaingui ... Now in Cmaingui if somebody presses pause, then i execute the following code ... thread doesn't stop execution and hence procedure doesnt stop execution. ...
    (microsoft.public.vc.mfc)
  • Re: I wanna implement the revolving slash while the process is executing
    ... complete the execution. ... I am interested in implementing something animate while users are ... waiting for the process to complete. ... If you have experience with Linux/Unix, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Need output from visual basic script
    ... I was already using that switch. ... switch causes cmd.exe to terminate after execution. ... but didn't address the problem of the Clipper program waiting ... swpruncmd op code to call cmd.exe to execute the script. ...
    (comp.lang.clipper)
  • I wanna implement the revolving slash while the process is executing
    ... I have a Windows console application, which takes around 3 minutes to ... complete the execution. ... I am interested in implementing something animate while users are ... waiting for the process to complete. ...
    (microsoft.public.dotnet.languages.csharp)