I have a panel called displayPanel
. In this panel I show a UserControl
depending on which button from a row of buttons is clicked using a method along the lines of:
private void button_Click(Object sender, EventArgs e)
{
displayPanel.Controls.Clear();
displayPanel.Controls.Add(UserControl);
}
In one of the user controls i had a method along the lines of:
private void StartWork()
{
Cursor.Current = Cursors.WaitCursor;
DoWork();
Cursor.Current = Curors.Default;
}
I then changed this to:
private async void StartWork(Object sender, EventArgs e)
{
Application.UseWaitCursor = true;
await DoWork();
Application.UseWaitCursor = false;
}
This allows me to change which UserControl
is displayed in the displayPanel
while DoWork()
is busy in the background. Starting DoWork()
and not changing usercontrols shows a wait cursor untill DoWork()
finishes, then its the default cursor again.
Starting DoWork()
and then changing the displayed usercontrol also shows the wait cursor untill DoWork()
is done, and then right back to the default cursor. However! If I now change back to the usercontrol that initiated DoWork()
then said usercontrol displays a wait cursor.
Printing all the UserWaitCursor
and Cursor
properties for the DoWork()
initiating usercontrol showns false
and Cursor.WaitCursor
respectively. (Instead of the expected: false
and Cursor.Default
)
Now I found that I can "Fix" my problem by calling UserControl.UseWaitCursor = !UserControl.UseWaitCursor
twice. But this feels wrong and I would rather fix it properly. Which brings me to my question: Why is my UserControl.Cursor
stuck at Cursor.WaitCursor
after setting Application.UseWaitCursor
to false in DoWork()
?
Edit: I made a simple project where I was able to reproduce the problem. In the following pastebin are a form and 2 usercontrols that are able to reproduce the discibed problem: http://pastebin.com/PUkvJxMw