Nice blocking UI

Boxerp has a responsiveness engine that lets you launch operations in background easily as displaying some kind of message to the user along with an option to cancel the call. However, there are times in which the operation is supposed to be fast so you don't launch a different thread but use the current one.
What happen then if the operation is delayed for any reason?. I think is nicer to show a message in the meanwhile, so I came up with this idea:

   1:  using (new WaitMessage())
   2:  {
   3:    // my potentially blocking code here
   4:  }
And the class for WPF:
   1:      public partial class WaitMessage : System.Windows.Window, IDisposable
   2:      {
   3:          public WaitMessage()
   4:          {
   5:              InitializeComponent();
   6:              Show();
   7:          }
   8:  
   9:          #region IDisposable Members
  10:  
  11:          public void Dispose()
  12:          {
  13:              Close();
  14:              GC.SuppressFinalize(this);
  15:          }
  16:  
  17:          // Deconstructor: make sure the window is disposed
  18:          ~WaitMessage()
  19:          {
  20:              Dispose();
  21:          }
  22:          #endregion
  23:      }

I haven't stress the window and I need to make sure the garbage collection is going to be ok but it is working so far. The window opens at the begining of the block displaying a message so that the user knows the application is supposed to be working ("Please wait..."), and it is closed at the end of the block. I'm going to add this feature to Boxerp making it extensible for Winfows Forms and Gtk#

Enjoyed reading this post?
Subscribe to the RSS feed and have all new posts delivered straight to you.
  • http://forexrobotsspot.info Leroy Pomykala

    What i do not understood is actually how you’re not actually much more well-liked than you may be now. You’re very intelligent. You realize thus considerably relating to this subject, made me personally consider it from numerous varied angles. Its like men and women aren’t fascinated unless it is one thing to do with Lady gaga! Your own stuffs excellent. Always maintain it up!