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

Commit c605837

Browse files
authored
Merge pull request #808 from github/fixes/usagetracker-dispatcher
Ensure UsageTracker time runs on main thread.
2 parents ee1cd91 + 2171293 commit c605837

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/GitHub.Exports/Helpers/ThreadingHelper.cs

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Windows;
88
using static Microsoft.VisualStudio.Threading.JoinableTaskFactory;
99
using static Microsoft.VisualStudio.Threading.AwaitExtensions;
10+
using System.Windows.Threading;
1011

1112
namespace GitHub.Helpers
1213
{
@@ -25,6 +26,11 @@ public static class ThreadingHelper
2526
{
2627
public static bool InUIThread => (!Guard.InUnitTestRunner && Application.Current.Dispatcher.CheckAccess()) || !(Guard.InUnitTestRunner);
2728

29+
/// <summary>
30+
/// Gets the Dispatcher for the main thread.
31+
/// </summary>
32+
public static Dispatcher MainThreadDispatcher => Application.Current.Dispatcher;
33+
2834
/// <summary>
2935
/// Switch to the UI thread using ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync
3036
/// Auto-disables switching when running in unit test mode

src/GitHub.VisualStudio/Services/UsageTracker.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public UsageTracker(IGitHubServiceProvider gitHubServiceProvider)
6565
TimeSpan.FromMinutes(3),
6666
DispatcherPriority.Background,
6767
TimerTick,
68-
Dispatcher.CurrentDispatcher);
68+
ThreadingHelper.MainThreadDispatcher);
6969

7070
RunTimer();
7171
}

0 commit comments

Comments
 (0)