My sixteenth How do I is up.
Scenario
It is always a best practice to inform the user what is going on when we need to perform a long running operation. For that purpose Visual Studio has the status bar:
There are several options when dealing with the Visual Studio status bar, we can write messages, display progress and animations, etc. The focus of this How do I tackles these scenarios.
Interfaces and classes needed
Code snippet
int frozen;
IVsStatusbar statusBar = serviceProvider.GetService(typeof(SVsStatusbar)) asIVsStatusbar;
statusBar.IsFrozen(out frozen);
//Write to the status bar
if(!Convert.ToBoolean(frozen))
{
statusBar.SetText(“The Message”);
//Do process
Thread.Sleep(5000);
statusBar.Clear();
}
//Write and display animatio in the status bar
if(!Convert.ToBoolean(frozen))
{
//The built icons that can be used are defined in Microsoft.VisualStudio.Shell.Interop.Constants.SBAI_*
object icon = (short)Microsoft.VisualStudio.Shell.Interop.Constants.SBAI_General;
statusBar.Animation(1, ref icon);
statusBar.SetText(“The Message”);
//Do process
Thread.Sleep(5000);
statusBar.Animation(0, ref icon);
statusBar.Clear();
}
//Display progress in the status bar
if(!Convert.ToBoolean(frozen))
{
uint userId = (uint)Microsoft.VisualStudio.Shell.Interop.Constants.VSCOOKIE_NIL;
for(int i = 1; i <= 10; i++)
{
statusBar.Progress(ref userId, 1, “The Message”, (uint)i * 10, (uint)100);
//Do process
Thread.Sleep(1000);
}
statusBar.Progress(ref userId, 0, string.Empty, 0, 0);
}
Assemblies needed
- Microsoft.VisualStudio.Shell.Interop, Version=7.1.40304.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Stay tuned,
Pablo


