while loop in threads - help please
Posted on 2004-09-28
In my project, I have to check if a particular condition is satisfied and take some action accordingly. Hence I have started a thread which continously checks for the condition as shown below:
UINT ThreadProc(LPVOID lp)
DWORD dwWaitResult = WaitForSingleObject(MonitorEvent,INFINITE);
//do the required action and ...reset event
MonitorEvent will be set in the part of the code where the required condition is met. Once the the event is fired, ThreadProc acts and does the required task and again has to wait till the event is fired again. This has to continue till application exists.
The result of the above code is that CPU time is getting consumed 100%.
Can anyone please suggest a better solution?
Thanks in anticipation of information.