Skip to content

Commit 0b83b9a

Browse files
committed
async package tool window invocation within command
1 parent 9ef521d commit 0b83b9a

File tree

2 files changed

+14
-23
lines changed

2 files changed

+14
-23
lines changed

SharedProject/Impl/TestContainerDiscovery/PackageInitializer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ public void Initialize()
4141

4242
if (File.Exists(outputWindowInitializedFile))
4343
{
44-
OutputToolWindowCommand.Instance.FindToolWindow();
44+
await OutputToolWindowCommand.Instance.FindToolWindowAsync();
4545
}
4646
else
4747
{
4848
// for first time users, the window is automatically docked
49-
OutputToolWindowCommand.Instance.ShowToolWindow();
49+
await OutputToolWindowCommand.Instance.ShowToolWindowAsync();
5050
File.WriteAllText(outputWindowInitializedFile, string.Empty);
5151
}
5252
}

SharedProject/Output/OutputToolWindowCommand.cs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.ComponentModel.Design;
33
using Microsoft.VisualStudio.Shell;
4+
using System.Threading.Tasks;
45
using Task = System.Threading.Tasks.Task;
56

67
namespace FineCodeCoverage.Output
@@ -82,39 +83,29 @@ public static async Task InitializeAsync(AsyncPackage package)
8283
/// <param name="e">The event args.</param>
8384
public void Execute(object sender, EventArgs e)
8485
{
85-
ShowToolWindow();
86+
_ = ThreadHelper.JoinableTaskFactory.RunAsync(ShowToolWindowAsync);
8687
}
8788

88-
public ToolWindowPane ShowToolWindow()
89+
public async Task<ToolWindowPane> ShowToolWindowAsync()
8990
{
90-
ToolWindowPane window = null;
91+
ToolWindowPane window = await package.ShowToolWindowAsync(typeof(OutputToolWindow), 0, true, package.DisposalToken);
9192

92-
package.JoinableTaskFactory.RunAsync(async delegate
93+
if ((null == window) || (null == window.Frame))
9394
{
94-
window = await package.ShowToolWindowAsync(typeof(OutputToolWindow), 0, true, package.DisposalToken);
95-
96-
if ((null == window) || (null == window.Frame))
97-
{
98-
throw new NotSupportedException($"Cannot create '{Vsix.Name}' output window");
99-
}
100-
});
95+
throw new NotSupportedException($"Cannot create '{Vsix.Name}' output window");
96+
}
10197

10298
return window;
10399
}
104100

105-
public ToolWindowPane FindToolWindow()
101+
public async Task<ToolWindowPane> FindToolWindowAsync()
106102
{
107-
ToolWindowPane window = null;
103+
ToolWindowPane window = await package.FindToolWindowAsync(typeof(OutputToolWindow), 0, true, package.DisposalToken);
108104

109-
package.JoinableTaskFactory.RunAsync(async delegate
105+
if ((null == window) || (null == window.Frame))
110106
{
111-
window = await package.FindToolWindowAsync(typeof(OutputToolWindow), 0, true, package.DisposalToken);
112-
113-
if ((null == window) || (null == window.Frame))
114-
{
115-
throw new NotSupportedException($"Cannot create '{Vsix.Name}' output window");
116-
}
117-
});
107+
throw new NotSupportedException($"Cannot create '{Vsix.Name}' output window");
108+
}
118109

119110
return window;
120111
}

0 commit comments

Comments
 (0)