In my program with a UI in WinForm. I set the cursor to a hourglass just before to launch a method in ThreadPool.
My code in UI thread to set the cursor looks like this :
Application.UseWaitCursor = true;
When the method is finished, i go back to the UI Thread to set the cursor to the normal case.
Application.UseWaitCursor = false;
My problem is the cursor stay to the Hourglass till I don't move the mouse. It's a little bit disturbing if the user wait on the end of the action without moving the mouse.
Anyone can help me ?
Jérôme
Actually, there is one more way to do it, which I found somewhere after hours of researching this problem.
Unfortunately, it is a hack.
Below is a method that I wrote that handles the problem.
/// <summary>
/// Call to toggle between the current cursor and the wait cursor
/// </summary>
/// <param name="control">The calling control.</param>
/// <param name="toggleWaitCursorOn">True for wait cursor, false for default.</param>
public static void UseWaitCursor(this Control control, bool toggleWaitCursorOn)
{
...
control.UseWaitCursor = toggleWaitCursorOn;
// Because of a weird quirk in .NET, just setting UseWaitCursor to false does not work
// until the cursor's position changes. The following line of code fakes that and
// effectively forces the cursor to switch back from the wait cursor to default.
if (!toggleWaitCursorOn)
Cursor.Position = Cursor.Position;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With