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;}
}