Automatically showing a wait cursor to indicate a long operation is occurring


/ Published in: C#
Save to your folder(s)

Great way to show the user that something is happening without too much tedious work. As simple to use as putting the following code in Form_Load:

AutoWaitCursor.Cursor = Cursors.WaitCursor;
AutoWaitCursor.Delay = new TimeSpan(0, 0, 0, 0, 25);
// Set the window handle to the handle of the main form in your application
AutoWaitCursor.MainWindowHandle = this.Handle;
AutoWaitCursor.Start();

(From the site)
It can be extremely tiresome to have to continually remember to set and unset the wait cursor for an application. If an exception occurs you have to remember to add a try finally block to restore the cursor, or if you popup a message box you must remember to change the cursor first otherwise the user will just sit there thinking the application is busy! These are just a few of the many irritations that I have tried to solve with the class below.

The class below automatically monitors the state of an application and sets and restores the cursor according to whether the application is busy or not. All that’s required are a few lines of setup code and your done (see the example in the class header). If you have a multithreaded application, it won't change the cursor unless the main input thread is blocked. Infact you can remove all of your cursor setting code everywhere!

URL: http://www.vbusers.com/codecsharp/codeget.asp?ThreadID=58&PostID=1&NumReplies=0

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.