Lloyd.NET

Programing experiments

Waitblock

Sometimes that’s the little thing that one find useful.
Here is such a thing!

 

In our app there are lots of time where an operation can be long and we needs to display a wait cursor (Note: unfortunately we use 3rd party data which are impossible to thread, literally!).

I often found this operation cumbersome. You know, store the original cursor, change the cursor, make a try/finally block, restore the original cursor.

So here is a very simple class which do just that very nicely, just with a single line using statement, as in:

using (new WaitCursorBlock()){…}

 

And here is the code of this simple class:

public class WaitCursorBlock : IDisposable{Cursor originalCursor;public WaitCursorBlock(){originalCursor = Mouse.OverrideCursor;Mouse.OverrideCursor = Cursors.Wait;}public void Dispose(){Mouse.OverrideCursor = originalCursor;}}

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: General | Source Code | WPF
Posted by lloyd on Sunday, March 01, 2009 12:09 AM
Permalink | Comments (0) | Post RSSRSS comment feed
Comments are closed