The text of this article is not in this database — only its details are. Read it on the old site: Lengthy Operation Windows Form Patterns
1 Comment
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment.
The text of this article is not in this database — only its details are. Read it on the old site: Lengthy Operation Windows Form Patterns
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment.
Jamie SnellPosted Sep 21, 2010, 11:40 AM
In the following scenario this way would set it back to the default cursor too early. <o:p> </o:p> public void Method1 {<o:p></o:p> using LengthyOperation {<o:p></o:p> Method2();<o:p></o:p> OtherLongRunningMethod();<o:p></o:p> }<o:p></o:p> }<o:p></o:p> <o:p> </o:p> public void Method2 {<o:p></o:p> using LengthyOperation {<o:p></o:p> //do work <o:p></o:p> }<o:p></o:p> }<o:p></o:p> <o:p> </o:p> You could keep track of the current cursor, and even give the ability to set different cursors.. for example the wait or the busy cursor<o:p></o:p> <o:p> </o:p> public class LengthyOperation : IDisposable<o:p></o:p> {<o:p></o:p> private Cursor _originalCursor;<o:p></o:p> private bool _isDisposed = false;<o:p></o:p> <o:p></o:p> public LengthyOperation ( Cursor newCursor )<o:p></o:p> {<o:p></o:p> _originalCursor = Cursor.Current;<o:p></o:p> Cursor.Current = newCursor;<o:p></o:p> }<o:p></o:p> <o:p></o:p> #region " IDisposable Support "<o:p></o:p> protected virtual void Dispose( bool disposing )<o:p></o:p> {<o:p></o:p> if ( !_isDisposed )<o:p></o:p> {<o:p></o:p> if ( disposing )<o:p></o:p> {<o:p></o:p> Cursor.Current = _originalCursor;<o:p></o:p> }<o:p></o:p> }<o:p></o:p> _isDisposed = true;<o:p></o:p> <o:p></o:p> }<o:p></o:p> <o:p></o:p> public void Dispose()<o:p></o:p> {<o:p></o:p> Dispose( true );<o:p></o:p> GC.SuppressFinalize( this );<o:p></o:p> }<o:p></o:p> <o:p></o:p> #endregion<o:p></o:p> }