In many places throughout my application I want to display a waitcursor, and as it is an MDI application I need to use Application.WaitCursor so that they don't try to do anything else until whatever it is the program is doing has ended.
However, a straight call to change the cursor does not work unless I call Application.DoEvents after each change of the cursor. For example, when closing the application I want to display the wait cursor whilst local settings are written to disk:
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
// Check if user meant to close the application
DialogResult result = MessageBox.Show("Are you sure you want to close?",
"My Application", MessageBoxButtons.YesNoCancel);
if (result == DialogResult.No || result == DialogResult.Cancel)
e.Cancel = true;
Application.UseWaitCursor = true;
Application.DoEvents(); // <-- without this, the cursor does not change
// If a data file is currently open, close it
// Save the local settings
There are hundreds of instances of this requirement, and I would like to get rid of them all if I can - anyone got any ideas?