Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 4cdb8f4

Browse files
committed
Specify UIThreadNormalPriority for methods that SwitchToMainThreadAsync
1 parent 7d4c45f commit 4cdb8f4

File tree

3 files changed

+36
-33
lines changed

3 files changed

+36
-33
lines changed

src/GitHub.InlineReviews/InlineReviewsPackage.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,19 @@ protected override async Task InitializeAsync(
3030

3131
// Avoid delays when there is ongoing UI activity.
3232
// See: https://github.com/github/VisualStudio/issues/1537
33-
await JoinableTaskFactory.RunAsync(VsTaskRunContext.UIThreadNormalPriority, async () =>
34-
{
35-
await JoinableTaskFactory.SwitchToMainThreadAsync();
36-
menuService.AddCommands(
37-
exports.GetExportedValue<INextInlineCommentCommand>(),
38-
exports.GetExportedValue<IPreviousInlineCommentCommand>());
39-
});
33+
await JoinableTaskFactory.RunAsync(VsTaskRunContext.UIThreadNormalPriority, InitializeMenus);
34+
}
35+
36+
async Task InitializeMenus()
37+
{
38+
var menuService = (IMenuCommandService)(await GetServiceAsync(typeof(IMenuCommandService)));
39+
var componentModel = (IComponentModel)(await GetServiceAsync(typeof(SComponentModel)));
40+
var exports = componentModel.DefaultExportProvider;
41+
42+
await JoinableTaskFactory.SwitchToMainThreadAsync();
43+
menuService.AddCommands(
44+
exports.GetExportedValue<INextInlineCommentCommand>(),
45+
exports.GetExportedValue<IPreviousInlineCommentCommand>());
4046
}
4147
}
4248
}

src/GitHub.InlineReviews/PullRequestStatusBarPackage.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using Microsoft.VisualStudio.Shell;
99
using Serilog;
1010
using Task = System.Threading.Tasks.Task;
11-
using GitHub.Helpers;
11+
using Microsoft.VisualStudio.Threading;
1212

1313
namespace GitHub.InlineReviews
1414
{
@@ -23,19 +23,20 @@ public class PullRequestStatusBarPackage : AsyncPackage
2323
/// Initialize the PR status UI on Visual Studio's status bar.
2424
/// </summary>
2525
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
26+
{
27+
// Avoid delays when there is ongoing UI activity.
28+
// See: https://github.com/github/VisualStudio/issues/1537
29+
await JoinableTaskFactory.RunAsync(VsTaskRunContext.UIThreadNormalPriority, InitializeStatusBar);
30+
}
31+
32+
async Task InitializeStatusBar()
2633
{
2734
var usageTracker = (IUsageTracker)await GetServiceAsync(typeof(IUsageTracker));
2835
var serviceProvider = (IGitHubServiceProvider)await GetServiceAsync(typeof(IGitHubServiceProvider));
2936
var barManager = new PullRequestStatusBarManager(usageTracker, serviceProvider);
3037

31-
// Avoid delays when there is ongoing UI activity.
32-
// See: https://github.com/github/VisualStudio/issues/1537
33-
await JoinableTaskFactory.RunAsync(VsTaskRunContext.UIThreadNormalPriority, async () =>
34-
{
35-
await JoinableTaskFactory.SwitchToMainThreadAsync();
36-
barManager.StartShowingStatus();
37-
});
38+
await JoinableTaskFactory.SwitchToMainThreadAsync();
39+
barManager.StartShowingStatus();
3840
}
39-
4041
}
4142
}

src/GitHub.VisualStudio/GitHubPackage.cs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
4141
await base.InitializeAsync(cancellationToken, progress);
4242
await GetServiceAsync(typeof(IUsageTracker));
4343

44-
// This package might be loaded on demand so we must await initialization of menus.
45-
await InitializeMenus();
44+
// Avoid delays when there is ongoing UI activity.
45+
// See: https://github.com/github/VisualStudio/issues/1537
46+
await JoinableTaskFactory.RunAsync(VsTaskRunContext.UIThreadNormalPriority, InitializeMenus);
4647
}
4748

4849
void LogVersionInformation()
@@ -59,21 +60,16 @@ async Task InitializeMenus()
5960
var componentModel = (IComponentModel)(await GetServiceAsync(typeof(SComponentModel)));
6061
var exports = componentModel.DefaultExportProvider;
6162

62-
// Avoid delays when there is ongoing UI activity.
63-
// See: https://github.com/github/VisualStudio/issues/1537
64-
await JoinableTaskFactory.RunAsync(VsTaskRunContext.UIThreadNormalPriority, async () =>
65-
{
66-
await JoinableTaskFactory.SwitchToMainThreadAsync();
67-
menuService.AddCommands(
68-
exports.GetExportedValue<IAddConnectionCommand>(),
69-
exports.GetExportedValue<IBlameLinkCommand>(),
70-
exports.GetExportedValue<ICopyLinkCommand>(),
71-
exports.GetExportedValue<ICreateGistCommand>(),
72-
exports.GetExportedValue<IOpenLinkCommand>(),
73-
exports.GetExportedValue<IOpenPullRequestsCommand>(),
74-
exports.GetExportedValue<IShowCurrentPullRequestCommand>(),
75-
exports.GetExportedValue<IShowGitHubPaneCommand>());
76-
});
63+
await JoinableTaskFactory.SwitchToMainThreadAsync();
64+
menuService.AddCommands(
65+
exports.GetExportedValue<IAddConnectionCommand>(),
66+
exports.GetExportedValue<IBlameLinkCommand>(),
67+
exports.GetExportedValue<ICopyLinkCommand>(),
68+
exports.GetExportedValue<ICreateGistCommand>(),
69+
exports.GetExportedValue<IOpenLinkCommand>(),
70+
exports.GetExportedValue<IOpenPullRequestsCommand>(),
71+
exports.GetExportedValue<IShowCurrentPullRequestCommand>(),
72+
exports.GetExportedValue<IShowGitHubPaneCommand>());
7773
}
7874

7975
async Task EnsurePackageLoaded(Guid packageGuid)

0 commit comments

Comments
 (0)