Setting and Restoring a Wait Cursor

Create a class which can be invoked with a using statement to set and restore a wait cursor
6/12/2009 8:54:00 AM

When executing a long running process a wait cursor is usually displayed. The class below implements the IDisposable interface to restore the mouse cursor when the long running process is complete. The class is invoked with a Using statement which guarantees that the cursor will be restored even if an exception occurs during the long running process. The cursor type is passed in through the constructor of the SetMouseCursor class.

code snippet 1 Invoke the class with a using statement as shown in the code below. The cursor will be restored automatically at the end of the using block. A wait cursor is used in this example, but it could be set to any valid cursor type.

code snippet 2 A simple but effective way to implement a wait cursor.

 

Development Tools

  • Visual Studio 2005
  •   .NET Framework 2.0
  •   Visual C# 2005
  •   Visual Basic 2005
  •   SQL Server 2005
  • MPLAB IDE
  •   C32 C Compiler
  •   MPASM Assembler