Are there any dangers in using Application.UseWaitCursor to turn off and on the hourglass mouse pointer?
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
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