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

Commit

Permalink
Merge pull request #808 from github/fixes/usagetracker-dispatcher
Browse files Browse the repository at this point in the history
Ensure UsageTracker time runs on main thread.
  • Loading branch information
shana authored Jan 30, 2017
2 parents ee1cd91 + 2171293 commit c605837
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/GitHub.Exports/Helpers/ThreadingHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -25,6 +26,11 @@ public static class ThreadingHelper
{
public static bool InUIThread => (!Guard.InUnitTestRunner && Application.Current.Dispatcher.CheckAccess()) || !(Guard.InUnitTestRunner);

/// <summary>
/// Gets the Dispatcher for the main thread.
/// </summary>
public static Dispatcher MainThreadDispatcher => Application.Current.Dispatcher;

/// <summary>
/// Switch to the UI thread using ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync
/// Auto-disables switching when running in unit test mode
Expand Down
2 changes: 1 addition & 1 deletion src/GitHub.VisualStudio/Services/UsageTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public UsageTracker(IGitHubServiceProvider gitHubServiceProvider)
TimeSpan.FromMinutes(3),
DispatcherPriority.Background,
TimerTick,
Dispatcher.CurrentDispatcher);
ThreadingHelper.MainThreadDispatcher);

RunTimer();
}
Expand Down

0 comments on commit c605837

Please sign in to comment.