Hi,
For those who are not familiar with MFC, the CWaitCursor class provides a way to show a wait cursor, which is usually displayed as an hourglass, while you’re doing a lengthy operation. There are plenty of ways to modify the pointing device’s cursor under C#, however, the one I’m going to bring up here is simple and straight forward that has been used over the past years for my programs.

using System;
using System.Threading;
using System.Windows.Forms;

/// <summary>
/// Provides a utility class to handle the pointing device's wait cursor.
/// </summary>
public class WaitCursor : IDisposable
{
    private static int refCount = 0;

    /// <summary>
    /// Initializes a new instance of the WaitCursor class.
    /// </summary>
    public WaitCursor()
    {
        Interlocked.Increment(ref refCount);
        Cursor.Current = Cursors.WaitCursor;
    }

    /// <summary>
    /// Sets the default cursor.
    /// </summary>
    public void Dispose()
    {
        if (Interlocked.Decrement(ref refCount) == 0)
            Cursor.Current = Cursors.Default;
    }
}

Finally, to use the WaitCursor class, you just do the following:

using (new WaitCursor())
{
    //Do a lengthy operation
}

That’s all for now, folks!

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Recent Tweets

The best thing about the "Windows 10 First Anniversary" update is the "Bash on Ubuntu on Windows". Impressive! Thank you @Canonical

Sponsors