From 2171293fc911b6c81bff806fd8791395d2499339 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Fri, 27 Jan 2017 15:07:20 +0100 Subject: [PATCH] Ensure UsageTracker time runs on main thread. --- src/GitHub.Exports/Helpers/ThreadingHelper.cs | 6 ++++++ src/GitHub.VisualStudio/Services/UsageTracker.cs | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/GitHub.Exports/Helpers/ThreadingHelper.cs b/src/GitHub.Exports/Helpers/ThreadingHelper.cs index 036a1b467c..bdd82d2a16 100644 --- a/src/GitHub.Exports/Helpers/ThreadingHelper.cs +++ b/src/GitHub.Exports/Helpers/ThreadingHelper.cs @@ -7,6 +7,7 @@ using System.Windows; using static Microsoft.VisualStudio.Threading.JoinableTaskFactory; using static Microsoft.VisualStudio.Threading.AwaitExtensions; +using System.Windows.Threading; namespace GitHub.Helpers { @@ -25,6 +26,11 @@ public static class ThreadingHelper { public static bool InUIThread => (!Guard.InUnitTestRunner && Application.Current.Dispatcher.CheckAccess()) || !(Guard.InUnitTestRunner); + /// + /// Gets the Dispatcher for the main thread. + /// + public static Dispatcher MainThreadDispatcher => Application.Current.Dispatcher; + /// /// Switch to the UI thread using ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync /// Auto-disables switching when running in unit test mode diff --git a/src/GitHub.VisualStudio/Services/UsageTracker.cs b/src/GitHub.VisualStudio/Services/UsageTracker.cs index 0ba41b2d02..a9567a24f0 100644 --- a/src/GitHub.VisualStudio/Services/UsageTracker.cs +++ b/src/GitHub.VisualStudio/Services/UsageTracker.cs @@ -65,7 +65,7 @@ public UsageTracker(IGitHubServiceProvider gitHubServiceProvider) TimeSpan.FromMinutes(3), DispatcherPriority.Background, TimerTick, - Dispatcher.CurrentDispatcher); + ThreadingHelper.MainThreadDispatcher); RunTimer(); }