I often use this code in winforms applications to wait for events, without using threads.
while(checkSomething()){
Application.DoEvents();
}
The program and pc is still responsive while the loop run, however if I look cpu usage in task managart, it usage is reported as 100% .
Do you know why this happens?
When you add this:
You’re basically saying to have the program process windows messages, as fast as possible, without anything stopping it until “checkSomething” returns true.
There are a lot of reasons to avoid
DoEvents– that being said, if you really plan to do this, you should try to give up some processing time in your loop: