1. Create a process:
: Afxbeginthread (bkthreadproc, this-> getsafehwnd ());
2. background process functions and event variables that control thread suspension, recovery, and exit:
Cevent g_eventthreadpause (false, true );
Cevent g_eventthreadquit (false, true );
Uint bkthreadproc (lpvoid pparam)
{
Trace ("START background thread. \ n ");
While (true)
{
// Check whether the backgound thread need to quit
If (: waitforsingleobject (g_eventthreadquit, 0) = wait_object_0)
{
// Clean resource before quiting background thread
Trace ("Quit background thread. \ n ");
Break;
}
// Check whether the backgound thread need to pause
: Waitforsingleobject (g_eventthreadpause, infinite );
//.......
// Do some background work here ......
//.......
// Sleep (1, 2000 );
}
Return 0;
}
3. Thread Suspension
G_eventthreadpause.resetevent ();
4. Restore the thread
G_eventthreadpause.setevent ();
5. Exit the thread
G_eventthreadpause.setevent ();
G_eventthreadquit.setevent ();