Question

I have a winforms application which makes calls to Application.DoEvents(). Now the app freezes around the time this method is called (no surprise).

However, this only happens on some machines. Is it fair to say that this would be due to machine itself or is it still down to the code/application.doevents()? In which case, it should be refactored to use backgroundworker.

Would this be a machine/environment issue or an oppurtunity to use backgroundworker?

Was it helpful?

Solution

Use a background worker if you can. DoEvents is a 'hack' to allow your application to remain responsive, and process WM_PAINT messages mostly, when it's doing something it should actually never be doing: blocking execution for more than a reasonable time during message processing in the main GUI loop. If DoEvents causes a hang instead of fixing it, you have too many messages spending way too much system power. Fork them out to background workers to fix all of it at once - it's just a matter of time before "some machines" becomes "most machines" otherwise.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top