Hi,

I'm updating an IM client C app (for Windows XP) so that when a users screensaver comes on their presence state changes from online to away.
What I've done so far is add:

while(TRUE){
        refreshAutoAway();
        Sleep(1000);
    }

to the end of the WinMain function.
This all does what I want until I exit the application, when the process remains running in windows task manager. If I remove this code the application closes cleanly.
So got a couple of queries - firstly, am I going about this in the 'right' way (ie is using sleep() the best thing to do in this case)? and secondly, how I can ensure my repeated call to the function closes correctly when the app is exited?
Just let me know if you need to see any more bits of the code.
Cheers & TIA,
Alex
ps. the last time I did anything with C was about 8 years ago at college - so please consider me a newbie! ;-)

since this is a normal windows program you could replace sleep with a timer (see SetTimer() in MSDN) that is triggered every xxx milliseconds, and move call to refreshAutoAway() inside the timer event handler. Then replace that loop with the message pump, calling PeekMessage(), which will block your program until a windows message is received.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.