Export (0) Print
Expand All

How to: Program the Progress Bar Region of the Status Bar

The Progress Bar region of the Visual Studio status bar displays the incremental progress of quick operations, for example, saving a file to disk.

To use the Progress Bar region of the Visual Studio status bar

  1. Obtain an instance of the IVsStatusbar interface, which is made available through the SVsStatusbar service.

  2. Initialize the progress bar to starting values by calling the Progress method.

  3. Update the progress bar as your operation proceeds by using the Progress method to set new values.

This example demonstrates how to initialize and update the progress bar.

void ProgressBarExample()
{
    IVsStatusbar statusBar =
        (IVsStatusbar)GetService(typeof(SVsStatusbar));
    uint cookie = 0;
    string label = "Progress bar label...";

    // Initialize the progress bar.
    statusBar.Progress(ref cookie, 1, "", 0, 0);

    for (uint i = 0, total = 100; i <= total; i++)
    {
        // Display incremental progress.
        statusBar.Progress(ref cookie, 1, label, i, total);
        System.Threading.Thread.Sleep(1);
    }

    // Clear the progress bar.
    statusBar.Progress(ref cookie, 0, "", 0, 0);
}

In the example, the code:

  • Obtains an instance of the IVsStatusbar interface from the SVsStatusbar service.

  • Initializes the progress bar to given starting values by calling the Progress method.

  • Simulates an operation by iterating through a for loop and updating the progress bar values by using the Progress method.

  • Clears the progress bar by using the Clear method.

Show:
© 2015 Microsoft