I have a problem with a MessageBox window changing my wait cursor back to default and not letting me override it again. If i comment out the "Are you sure" message box the wait cursor works as intended (wait cursor is visible during the long running method). However with the program as normal no matter what i do the mouse is always default.
private void btn_Click(object sender, EventArgs e)
{
this.Cursor = Cursors.WaitCursor;
if (string.IsNullOrWhiteSpace(textbox1.Text))
{
MessageBox.Show("Text Box 1 Can't Be Empty");
}
else if (string.IsNullOrWhiteSpace(textbox3.Text))
{
MessageBox.Show("Text Box 3 Can't Be Empty");
}
else if (string.IsNullOrWhiteSpace(textbox4.Text))
{
MessageBox.Show("Text Box 4 can't be empty");
}
else if (string.IsNullOrWhiteSpace(textBox2.Text))
{
HelperClass.MethodThatCanHandleEmptyTextBox2(textBox1.Text, textBox3.Text, textBox4.Text));
}
else
{
//problem line
DialogResult result = MessageBox.Show("Are you sure you wish to proceed?", "Are You Sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
if (result == DialogResult.Yes)
{
this.Cursor = Cursors.WaitCursor; //doesn't work
//long running method
HelperClass.DoMethodThatNeedsAllFields(textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text); //long running method
MessageBox.Show("All done!");
}
}
this.Cursor = Cursors.Default;
}
I have tried all of these both inside and outside of the if (result == yes) condition, but to no avail:
Cursor = Cursors.WaitCursor;
Form1.ActiveForm.UseWaitCursor = true; //throws runtime exception
Cursor.Current = Cursors.WaitCursor;
Application.UseWaitCursor = true;
Application.DoEvents();
I have also tried threads AND tasks but neither of those have worked as well. Is there something I'm missing?