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

Commit 2a3cef5

Browse files
committed
Factor out GetServiceAsync
1 parent dcd806f commit 2a3cef5

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/GitHub.TeamFoundation.14/Services/VSGitExt.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,7 @@ async Task ContextChangedAsync()
9999

100100
async Task<bool> TryInitialize()
101101
{
102-
// GetService must be called on the Main thread.
103-
await ThreadingHelper.SwitchToMainThreadAsync();
104-
105-
gitService = serviceProvider.GetService<IGitExt>();
102+
gitService = await GetServiceAsync<IGitExt>();
106103
if (gitService != null)
107104
{
108105
gitService.PropertyChanged += (s, e) =>
@@ -125,6 +122,13 @@ async Task<bool> TryInitialize()
125122
return false;
126123
}
127124

125+
async Task<T> GetServiceAsync<T>() where T : class
126+
{
127+
// GetService must be called from the Main thread.
128+
await ThreadingHelper.SwitchToMainThreadAsync();
129+
return serviceProvider.GetService<T>();
130+
}
131+
128132
void RefreshActiveRepositories()
129133
{
130134
try

0 commit comments

Comments
 (0)