A "thread", in operating system parlance, is another execution context. It
has its own stack, it's own program counter, etc. It is scheduled
separately from the main thread which your user interface is using, and runs
'at the same time' as other threads in the system. It allows you to perform
some action in a separate execution context from that used to respond to
user interface operations, thus keeping the work that the thread is doing
separate from what's going on in the UI. As it happens, threads are
implemented in such a way that they execute in the context of a single
function (they can call other functions, of course), called when the thread
starts and causing the thread to exit when they exit. Yours might be
roughly something like the below:
int MyThread()
{
// The Wait delays either 5 seconds or until the exitEvent is set. In
the main thread
// (the user interface thread), when it's time to exit this thread, you
set the exitEvent
// to notify the thread to leave.
while ( WaitForSingleObject( exitEvent, 5000 /* 5 seconds between loops
*/ ) == WAIT_TIMEOUT )
{
// Do whatever you do in each loop.
}
// When the exitEvent is 'set', the loop exits, and you return from the
thread function,
// ending the thread.
return 0;
}
Paul T.