Display Hourglass When Application Is Busy

display Hourglass when application is busy

We did a disposable class that changes the cursor for us when the app is going to take long, it looks like this:

public class WaitCursor : IDisposable
{
private Cursor _previousCursor;

public WaitCursor()
{
_previousCursor = Mouse.OverrideCursor;

Mouse.OverrideCursor = Cursors.Wait;
}

#region IDisposable Members

public void Dispose()
{
Mouse.OverrideCursor = _previousCursor;
}

#endregion
}

And we use it like this:

using(new WaitCursor())
{
// very long task
}

Might not be the greatest design, but it does the trick =)

How to show a waitcursor when the WPF application is busy databinding

Isak's answer did not work for me, because it did not solve the problem of how to act when the actual wait is over for the user.
I ended up doing this: Everytime I start doing something timeconsuming, I call a helper-method. This helper method changes the cursor and then creates a DispatcherTimer that will be called when the application is idle. When it is called it sets the mousecursor back:

/// <summary>
/// Contains helper methods for UI, so far just one for showing a waitcursor
/// </summary>
public static class UiServices
{

/// <summary>
/// A value indicating whether the UI is currently busy
/// </summary>
private static bool IsBusy;

/// <summary>
/// Sets the busystate as busy.
/// </summary>
public static void SetBusyState()
{
SetBusyState(true);
}

/// <summary>
/// Sets the busystate to busy or not busy.
/// </summary>
/// <param name="busy">if set to <c>true</c> the application is now busy.</param>
private static void SetBusyState(bool busy)
{
if (busy != IsBusy)
{
IsBusy = busy;
Mouse.OverrideCursor = busy ? Cursors.Wait : null;

if (IsBusy)
{
new DispatcherTimer(TimeSpan.FromSeconds(0), DispatcherPriority.ApplicationIdle, dispatcherTimer_Tick, Application.Current.Dispatcher);
}
}
}

/// <summary>
/// Handles the Tick event of the dispatcherTimer control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
private static void dispatcherTimer_Tick(object sender, EventArgs e)
{
var dispatcherTimer = sender as DispatcherTimer;
if (dispatcherTimer != null)
{
SetBusyState(false);
dispatcherTimer.Stop();
}
}
}

Display a wait cursor while form is busy

Unless you are want to run your long processes on another thread you only have to stick in a Application.DoEvents() line after changing the cursor and before the long process.

Cursor = Cursors.WaitCursor 'and some various me.Cursor / current.cursor 
Application.DoEvents()
CalulateBalance()
FTableAdapter.FillDateID(BudgetDataSet.FQuartaly)
FQuartalyDataGridView.Refresh()
MsgBox("Completed updating Balances", MsgBoxStyle.OkOnly)
Cursor = Cursors.Default

How do show excel is working with the busy (hourglass) mouse cursor when running a python script in xlwings?

Sadly, xkwings does not yet support this: an issue to do so was created in Oct 27, 2016 but is not yet resolved:

  • http://github.com/xlwings/xlwings/issues/578

How can I make the cursor turn to the wait cursor?

You can use Cursor.Current.

// Set cursor as hourglass
Cursor.Current = Cursors.WaitCursor;

// Execute your time-intensive hashing code here...

// Set cursor as default arrow
Cursor.Current = Cursors.Default;

However, if the hashing operation is really lengthy (MSDN defines this as more than 2-7 seconds), you should probably use a visual feedback indicator other than the cursor to notify the user of the progress. For a more in-depth set of guidelines, see this article.

Edit:
As @Am pointed out, you may need to call Application.DoEvents(); after Cursor.Current = Cursors.WaitCursor; to ensure that the hourglass is actually displayed.

Hourglass cursor in VB.NET

You can use either

Me.Cursor = Cursors.AppStarting

or

Me.Cursor = Cursors.WaitCursor

To set it back to the normal cursor:

Me.Cursor = Cursors.Default

Change cursor to hourglass/wait/busy cursor and back in Qt

Qsiris solution is "widget wide". If you want to change cursor for your whole application then use

QApplication::setOverrideCursor(Qt::WaitCursor);

and

QApplication::restoreOverrideCursor();

Note: As @Ehsan Khodarahmi pointed out, the cursor will NOT change until triggering next QT event or calling QApplication::processEvents() manually.



Related Topics



Leave a reply



Submit