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

Commit 1ef04a4

Browse files
committed
GetService must called be on main thread.
1 parent 91d86ab commit 1ef04a4

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/GitHub.VisualStudio/Services/UsageService.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Text;
66
using System.Threading;
77
using System.Threading.Tasks;
8+
using GitHub.Helpers;
89
using GitHub.Models;
910
using Task = System.Threading.Tasks.Task;
1011

@@ -54,7 +55,7 @@ public IDisposable StartTimer(Func<Task> callback, TimeSpan dueTime, TimeSpan pe
5455

5556
public async Task<UsageData> ReadLocalData()
5657
{
57-
Initialize();
58+
await Initialize();
5859

5960
var json = File.Exists(storePath) ? await ReadAllTextAsync(storePath) : null;
6061

@@ -84,10 +85,12 @@ public async Task WriteLocalData(UsageData data)
8485
}
8586
}
8687

87-
void Initialize()
88+
async Task Initialize()
8889
{
8990
if (storePath == null)
9091
{
92+
await ThreadingHelper.SwitchToMainThreadAsync();
93+
9194
var program = serviceProvider.GetService<IProgram>();
9295
storePath = Path.Combine(
9396
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),

0 commit comments

Comments
 (0)