How do I flush content to the Visual Studio output window
My fifth How do I is up.
Scenario
Every time that we write to the Visual Studio output window, the content is not flushed automatically. Sometimes this can be resolved by the Application.DoEvents(); call. But this method doesn't work in a number of scenarios. The focus of this How do I tackles how to approach this problem.
Interfaces and classes needed
Code snippet
Automation way
DTE2 dte = serviceProvider.GetService(typeof(SDTE)) as DTE2;
OutputWindowPane generalPane =
dte.ToolWindows.OutputWindow.OutputWindowPanes.OfType<OutputWindowPane>()
.FirstOrDefault(pane =>
new Guid(pane.Guid).Equals(VSConstants.GUID_OutWindowGeneralPane));
if(generalPane != null)
{
generalPane.OutputString("Test");
generalPane.ForceItemsToTaskList();
}
Assemblies needed
Interop way
IVsOutputWindow outputwindow = serviceProvider.GetService(typeof(SVsOutputWindow)) as IVsOutputWindow;
Guid generalGuidPane = VSConstants.GUID_OutWindowGeneralPane;
IVsOutputWindowPane generalPane;
ErrorHandler.ThrowOnFailure(outputwindow.GetPane(ref generalGuidPane, out generalPane));
generalPane.OutputStringThreadSafe("Test");
ErrorHandler.ThrowOnFailure(generalPane.FlushToTaskList());
Assemblies needed
- Microsoft.VisualStudio.Shell.Interop
- Microsoft.VisualStudio.Shell.9.0
Stay tuned,
Pablo