Developer, Former MVP, now at Microsoft - Best of 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
void SomeMethod(){ Cursor.Current = Cursors.WaitCursor; statusBar1.Text = "Busy..."; button1.Enabled = false; // do some real work here button1.Enabled = true; statusBar1.Text = "Ready"; Cursor.Current = Cursors.Default;}
void SomeMethod(){ using (BusyTaskRegion bt = new BusyTaskRegion(statusBar1, button1)) { // do some real work here }}
class BusyTaskRegion : IDisposable{ private Control _c1; private Control _c2; public BusyTaskRegion(Control c1, Control c2) { this._c1 = c1; this._c2 = c2; Cursor.Current = Cursors.WaitCursor; c1.Text = "Busy..."; c2.Enabled = false; } public void Dispose() { this._c1.Enabled = true; this._c1.Text = "Ready"; Cursor.Current = Cursors.Default; }}