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

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

src/GitHub.VisualStudio/UI/GitHubPane.cs

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
using System;
2+
using System.Threading.Tasks;
23
using System.ComponentModel.Design;
34
using System.Diagnostics.CodeAnalysis;
45
using System.Reactive.Linq;
56
using System.Runtime.InteropServices;
67
using System.Windows;
78
using System.Windows.Controls;
8-
using GitHub.Extensions;
99
using GitHub.Factories;
1010
using GitHub.Services;
11-
using GitHub.ViewModels;
1211
using GitHub.ViewModels.GitHubPane;
1312
using Microsoft.VisualStudio.Shell;
1413
using Microsoft.VisualStudio.Shell.Interop;
1514
using Microsoft.VisualStudio.ComponentModelHost;
15+
using Microsoft.VisualStudio.Threading;
1616
using ReactiveUI;
17-
using Task = System.Threading.Tasks.Task;
1817
using IAsyncServiceProvider = Microsoft.VisualStudio.Shell.IAsyncServiceProvider;
19-
using System.Threading.Tasks;
2018

2119
namespace GitHub.VisualStudio.UI
2220
{
@@ -36,8 +34,7 @@ public class GitHubPane : ToolWindowPane
3634
{
3735
public const string GitHubPaneGuid = "6b0fdc0a-f28e-47a0-8eed-cc296beff6d2";
3836

39-
readonly TaskCompletionSource<IGitHubPaneViewModel> viewModelSource =
40-
new TaskCompletionSource<IGitHubPaneViewModel>();
37+
JoinableTask<IGitHubPaneViewModel> viewModelTask;
4138

4239
IDisposable viewSubscription;
4340
ContentPresenter contentPresenter;
@@ -83,30 +80,38 @@ public GitHubPane() : base(null)
8380

8481
protected override void Initialize()
8582
{
86-
InitializeAsync().Catch(ShowError).Forget();
83+
viewModelTask = ThreadHelper.JoinableTaskFactory.RunAsync(InitializeAsync);
8784
}
8885

89-
public Task<IGitHubPaneViewModel> GetViewModelAsync() => viewModelSource.Task;
86+
public Task<IGitHubPaneViewModel> GetViewModelAsync() => viewModelTask.JoinAsync();
9087

91-
async Task InitializeAsync()
88+
async Task<IGitHubPaneViewModel> InitializeAsync()
9289
{
93-
// Allow MEF to initialize its cache asynchronously
94-
ShowInitializing();
95-
var asyncServiceProvider = (IAsyncServiceProvider)GetService(typeof(SAsyncServiceProvider));
96-
await asyncServiceProvider.GetServiceAsync(typeof(SComponentModel));
90+
try
91+
{
92+
// Allow MEF to initialize its cache asynchronously
93+
ShowInitializing();
94+
var asyncServiceProvider = (IAsyncServiceProvider)GetService(typeof(SAsyncServiceProvider));
95+
await asyncServiceProvider.GetServiceAsync(typeof(SComponentModel));
9796

98-
var provider = VisualStudio.Services.GitHubServiceProvider;
99-
var teServiceHolder = provider.GetService<ITeamExplorerServiceHolder>();
100-
teServiceHolder.ServiceProvider = this;
97+
var provider = VisualStudio.Services.GitHubServiceProvider;
98+
var teServiceHolder = provider.GetService<ITeamExplorerServiceHolder>();
99+
teServiceHolder.ServiceProvider = this;
101100

102-
var factory = provider.GetService<IViewViewModelFactory>();
103-
var viewModel = provider.ExportProvider.GetExportedValue<IGitHubPaneViewModel>();
104-
await viewModel.InitializeAsync(this);
101+
var factory = provider.GetService<IViewViewModelFactory>();
102+
var viewModel = provider.ExportProvider.GetExportedValue<IGitHubPaneViewModel>();
103+
await viewModel.InitializeAsync(this);
105104

106-
View = factory.CreateView<IGitHubPaneViewModel>();
107-
View.DataContext = viewModel;
105+
View = factory.CreateView<IGitHubPaneViewModel>();
106+
View.DataContext = viewModel;
108107

109-
viewModelSource.SetResult(viewModel);
108+
return viewModel;
109+
}
110+
catch (Exception e)
111+
{
112+
ShowError(e);
113+
throw;
114+
}
110115
}
111116

112117
[SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "WTF CA, I'm overriding!")]

0 commit comments

Comments
 (0)