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

Commit cfe23e1

Browse files
committed
Initialize menus on Main thread
Avoid using SwitchToMainThreadAsync because it can hang when called before a solution is loaded.
1 parent 5ad71c4 commit cfe23e1

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

src/GitHub.InlineReviews/InlineReviewsPackage.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313

1414
namespace GitHub.InlineReviews
1515
{
16-
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
16+
// Initialize menus on Main thread.
17+
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = false)]
1718
[Guid(Guids.InlineReviewsPackageId)]
1819
[ProvideAutoLoad(UIContextGuids80.SolutionExists)]
1920
[ProvideMenuResource("Menus.ctmenu", 1)]
@@ -24,12 +25,10 @@ protected override async Task InitializeAsync(
2425
CancellationToken cancellationToken,
2526
IProgress<ServiceProgressData> progress)
2627
{
27-
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
28-
2928
var menuService = (IMenuCommandService)(await GetServiceAsync(typeof(IMenuCommandService)));
3029
var componentModel = (IComponentModel)(await GetServiceAsync(typeof(SComponentModel)));
31-
var exports = componentModel.DefaultExportProvider;
3230

31+
var exports = componentModel.DefaultExportProvider;
3332
menuService.AddCommands(
3433
exports.GetExportedValue<INextInlineCommentCommand>(),
3534
exports.GetExportedValue<IPreviousInlineCommentCommand>());

src/GitHub.VisualStudio/GitHubPackage.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@
2424

2525
namespace GitHub.VisualStudio
2626
{
27-
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
27+
// Initialize menus on Main thread.
28+
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = false)]
2829
[InstalledProductRegistration("#110", "#112", AssemblyVersionInformation.Version, IconResourceID = 400)]
2930
[Guid(Guids.guidGitHubPkgString)]
3031
[ProvideMenuResource("Menus.ctmenu", 1)]
3132
// Only initialize when we're in the context of a Git repository.
32-
[ProvideAutoLoad(Guids.UIContext_Git, PackageAutoLoadFlags.BackgroundLoad)]
33+
[ProvideAutoLoad(Guids.UIContext_Git)]
3334
[ProvideToolWindow(typeof(GitHubPane), Orientation = ToolWindowOrientation.Right, Style = VsDockStyle.Tabbed, Window = EnvDTE.Constants.vsWindowKindSolutionExplorer)]
3435
[ProvideOptionPage(typeof(OptionsPage), "GitHub for Visual Studio", "General", 0, 0, supportsAutomation: true)]
3536
public class GitHubPackage : AsyncPackage
@@ -71,9 +72,6 @@ async Task InitializeMenus()
7172
var menuService = (IMenuCommandService)(await GetServiceAsync(typeof(IMenuCommandService)));
7273
var componentModel = (IComponentModel)(await GetServiceAsync(typeof(SComponentModel)));
7374

74-
// IMenuCommandService.AddCommand uses IServiceProvider.GetService and must be called on Main thread.
75-
await ThreadingHelper.SwitchToMainThreadAsync();
76-
7775
var exports = componentModel.DefaultExportProvider;
7876
menuService.AddCommands(
7977
exports.GetExportedValue<IAddConnectionCommand>(),

0 commit comments

Comments
 (0)