Click to See Complete Forum and Search --> : a problem


field_hawk
October 30th, 2002, 09:30 AM
hello

is it possible in c++ after a certain time the input is over
i,e when user does not any thing for specified time the massage be displayed "Time is over"

kuphryn
October 30th, 2002, 01:42 PM
Yes. Your problem is a related to design, not implementation.

As for implementation, I recommend a timer queue if the application runs in NT and newer versions of Windows. Otherwise, implement a worker thread to do the counting.

Kuphryn

doublehook
October 30th, 2002, 06:03 PM
In Windows:

// Application symbol TimeOut is 60 seconds
#define TimeOut 60000

// Application global data
DWORD LastTime;

In the main function you set first a value to LastTime:

LastTime = GetTickCount();

Each time your program receives user input updates LastTime:

LastTime = GetTickCount();

A second thread have a loop that compares:

if ((GetTickCount() - LastTime) >= TimeOut)
{
// make something to notify or display a message
// you can break the loop and end the thread
// or you can set LastTime = GetTickCount() again
// and continue the loop
}