Is Application.DoEvents() just for WinForms?

Jaime Oro picture Jaime Oro · Feb 12, 2011 · Viewed 18.1k times · Source

Is Application.DoEvents() just for forms?

I thought that this command was used to ensure that all of the commands before are processed but now after reading the documentation, I'm not sure anymore.

Answer

Jon Skeet picture Jon Skeet · Feb 12, 2011

Yes, it's really aimed at Windows Forms. However, in my view it should be avoided where possible.

It's usually used as a hack by developers who don't want to be bothered with putting long-running operations on a different thread... but that means they're introducing re-entrancy issues which can be very hard to track down, as well as still blocking the UI thread for some of the time (and if that includes something like a file operation, you can't really predict whether the operation will complete quickly enough to not have a user visible effect).