11using System ;
2+ using System . Threading . Tasks ;
23using System . ComponentModel . Design ;
34using System . Diagnostics . CodeAnalysis ;
45using System . Reactive . Linq ;
56using System . Runtime . InteropServices ;
67using System . Windows ;
78using System . Windows . Controls ;
8- using GitHub . Extensions ;
99using GitHub . Factories ;
1010using GitHub . Services ;
11- using GitHub . ViewModels ;
1211using GitHub . ViewModels . GitHubPane ;
1312using Microsoft . VisualStudio . Shell ;
1413using Microsoft . VisualStudio . Shell . Interop ;
1514using Microsoft . VisualStudio . ComponentModelHost ;
15+ using Microsoft . VisualStudio . Threading ;
1616using ReactiveUI ;
17- using Task = System . Threading . Tasks . Task ;
1817using IAsyncServiceProvider = Microsoft . VisualStudio . Shell . IAsyncServiceProvider ;
19- using System . Threading . Tasks ;
2018
2119namespace 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