Should Application.UseWaitCursor be used?
Solution 1:
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
Solution 2:
If the application will be locked until the long running operation is completed, it will be correct to use Application.UseWaitCursor
. But if you have multiple forms where only one form will be locked, it is better to set the Cursor
property explicit on the form.
You should also remeber to put Application.UseWaitCursor = false;
in a finally
block, so you ensure that the cursor is reset in cases where an application exception is thrown.