@@ -38,14 +38,11 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
3838 LogVersionInformation ( ) ;
3939 await base . InitializeAsync ( cancellationToken , progress ) ;
4040 await GetServiceAsync ( typeof ( IUsageTracker ) ) ;
41- await InitializeMenus ( ) ;
42- }
4341
44- // The IDesignerHost and ISelectionService services are requested by MenuCommandService.EnsureVerbs().
45- // When called from a non-Main thread this would throw despite the fact these services don't exist.
46- // This override allows IMenuCommandService.AddCommands to be called form a background thread.
47- protected override object GetService ( Type serviceType )
48- => ( serviceType == typeof ( ISelectionService ) || serviceType == typeof ( IDesignerHost ) ) ? null : base . GetService ( serviceType ) ;
42+ // Avoid delays when there is ongoing UI activity.
43+ // See: https://github.com/github/VisualStudio/issues/1537
44+ await JoinableTaskFactory . RunAsync ( VsTaskRunContext . UIThreadNormalPriority , InitializeMenus ) ;
45+ }
4946
5047 void LogVersionInformation ( )
5148 {
@@ -60,16 +57,20 @@ async Task InitializeMenus()
6057 var menuService = ( IMenuCommandService ) ( await GetServiceAsync ( typeof ( IMenuCommandService ) ) ) ;
6158 var componentModel = ( IComponentModel ) ( await GetServiceAsync ( typeof ( SComponentModel ) ) ) ;
6259 var exports = componentModel . DefaultExportProvider ;
63-
64- menuService . AddCommands (
60+ var commands = new IVsCommandBase [ ]
61+ {
6562 exports . GetExportedValue < IAddConnectionCommand > ( ) ,
6663 exports . GetExportedValue < IBlameLinkCommand > ( ) ,
6764 exports . GetExportedValue < ICopyLinkCommand > ( ) ,
6865 exports . GetExportedValue < ICreateGistCommand > ( ) ,
6966 exports . GetExportedValue < IOpenLinkCommand > ( ) ,
7067 exports . GetExportedValue < IOpenPullRequestsCommand > ( ) ,
7168 exports . GetExportedValue < IShowCurrentPullRequestCommand > ( ) ,
72- exports . GetExportedValue < IShowGitHubPaneCommand > ( ) ) ;
69+ exports . GetExportedValue < IShowGitHubPaneCommand > ( )
70+ } ;
71+
72+ await JoinableTaskFactory . SwitchToMainThreadAsync ( ) ;
73+ menuService . AddCommands ( commands ) ;
7374 }
7475
7576 async Task EnsurePackageLoaded ( Guid packageGuid )
0 commit comments