WaitCursorChanger.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Windows.Forms;
  3. namespace SmartCoalApplication.Core
  4. {
  5. public sealed class WaitCursorChanger : IDisposable
  6. {
  7. private Control control;
  8. private Cursor oldCursor;
  9. private static int nextID = 0;
  10. private int id = System.Threading.Interlocked.Increment(ref nextID);
  11. public WaitCursorChanger(Control control)
  12. {
  13. this.control = control;
  14. this.oldCursor = Cursor.Current;
  15. Cursor.Current = Cursors.WaitCursor;
  16. }
  17. ~WaitCursorChanger()
  18. {
  19. Dispose(false);
  20. }
  21. public void Dispose()
  22. {
  23. Dispose(true);
  24. GC.SuppressFinalize(this);
  25. }
  26. private void Dispose(bool disposing)
  27. {
  28. if (disposing)
  29. {
  30. if (this.oldCursor != null)
  31. {
  32. Cursor.Current = this.oldCursor;
  33. this.oldCursor = null;
  34. }
  35. }
  36. }
  37. }
  38. }