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

Commit ebbc6a6

Browse files
committed
Let PR # appear on status bar before solution has loaded
ThreadingHelper.SwitchToMainThreadAsync() only returns when a solution has loaded. Use Application.Current.Dispatcher.Invoke instead of ThreadingHelper.SwitchToMainThreadAsync.
1 parent 2df68b1 commit ebbc6a6

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/GitHub.InlineReviews/PullRequestStatusBarPackage.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
2+
using System.Windows;
23
using System.Threading;
34
using System.Runtime.InteropServices;
4-
using GitHub.Helpers;
55
using GitHub.Services;
66
using GitHub.VisualStudio;
77
using GitHub.InlineReviews.Services;
@@ -23,9 +23,12 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
2323
var usageTracker = (IUsageTracker)await GetServiceAsync(typeof(IUsageTracker));
2424
var serviceProvider = (IGitHubServiceProvider)await GetServiceAsync(typeof(IGitHubServiceProvider));
2525

26-
await ThreadingHelper.SwitchToMainThreadAsync();
27-
var gitExt = serviceProvider.GetService<IVSGitExt>();
28-
new PullRequestStatusBarManager(gitExt, usageTracker, serviceProvider);
26+
// NOTE: ThreadingHelper.SwitchToMainThreadAsync() doesn't return until a solution is loaded. Using Dispatcher.Invoke instead.
27+
Application.Current.Dispatcher.Invoke(() =>
28+
{
29+
var gitExt = serviceProvider.GetService<IVSGitExt>();
30+
new PullRequestStatusBarManager(gitExt, usageTracker, serviceProvider);
31+
});
2932
}
3033
}
3134
}

src/GitHub.InlineReviews/Services/PullRequestStatusBarManager.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
using GitHub.VisualStudio;
1212
using GitHub.Models;
1313
using GitHub.Logging;
14-
using GitHub.Helpers;
1514
using GitHub.Extensions;
1615
using Serilog;
17-
using Task = System.Threading.Tasks.Task;
1816

1917
namespace GitHub.InlineReviews.Services
2018
{
@@ -44,17 +42,15 @@ void OnActiveRepositoriesChanged()
4442
{
4543
if (gitExt.ActiveRepositories.Count > 0)
4644
{
47-
StartShowingStatus().Forget();
4845
gitExt.ActiveRepositoriesChanged -= OnActiveRepositoriesChanged;
46+
Application.Current.Dispatcher.Invoke(() => StartShowingStatus());
4947
}
5048
}
5149

52-
async Task StartShowingStatus()
50+
void StartShowingStatus()
5351
{
5452
try
5553
{
56-
await ThreadingHelper.SwitchToMainThreadAsync(); // Switch from VSGitExt to Main thread
57-
5854
// Create just in time on Main thread.
5955
pullRequestSessionManager = serviceProvider.GetService<IPullRequestSessionManager>();
6056

0 commit comments

Comments
 (0)