Click to See Complete Forum and Search --> : Terminating a program


ProgrammingAce
03-12-2003, 11:44 PM
What is one way to stop a program that operates in a forever loop? I have a program that does some things (create handles, initalize variables, etc) that then goes into a for-loop. After the for-loop expires, I close the handles and such.

What I want to do is change this for-loop into a forever loop that can be stopped by the user (pushing one of the physical buttons or something like that). I guess polling the software keyboard for a certain keypress at the end of the forever loop would be okay, but I dont know how to do that in this environment. Any possible ideas other than displaying a message box/input box at the end of each cycle? I have been using pure windows API (its a college project and I dont have enough time to learn MFC or something like that).

srouleau
03-13-2003, 09:45 AM
Ace,

Having a program constantly run like that is a drain on the battery. Buf if this is something you want/have to do, then there's several ways of doing this.

One way would be for you to assign an application to an hardware button; when the button is pressed, the application sets an event (see "SetEvent()"). Your forever-loop would then check if the event has been set.

There you go, you first inter-process communication.

ProgrammingAce
03-13-2003, 03:28 PM
Yes, I need the program to be running continously because it will be gathering data for a few hours or so (depends on how long the batteries will last). I already know how to disable the auto-power-down feature manually, but I have not found a way to set that through my program (I assume to would require modifying the registry).

Thanks for the suggestion. I'll look into the SetEvent() function.

srouleau
03-13-2003, 04:21 PM
You may want to look at the SystemParametersInfo() to disable to automatic power off. That's how you do it on the Smartphone 2002, it's probably the same on a PocketPC 2002.