Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should Application.UseWaitCursor be used?

Are there any dangers in using Application.UseWaitCursor to turn off and on the hourglass mouse pointer?

like image 713
CJ7 Avatar asked Jun 14 '26 16:06

CJ7


1 Answers

The "danger" is in not restoring the cursor.

You can do this with try…finally blocks to ensure that even if an exception is thrown you restore the cursor, or clean up the syntax a bit by wrapping this functionality in a class that implements IDisposable so that you can use using blocks instead.

  public class WaitCursor : IDisposable
  {
    public WaitCursor()
    {
      Application.UseWaitCursor = true;
    }

    public void Dispose()
    {
      Application.UseWaitCursor = false;
    }
  }

Usage:

  using (new WaitCursor())
  {

    // do stuff - busy, busy, busy

  } // here the cursor will be restored no matter what happened
like image 62
Jay Avatar answered Jun 16 '26 10:06

Jay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!