Skip to content

Commit

Permalink
Updated DispatcherTimer for Windows to support providing a different …
Browse files Browse the repository at this point in the history
…CoreDispatcher.
  • Loading branch information
jamesmcroft committed Apr 7, 2019
1 parent d9e47a0 commit 6746f84
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions XPlat.UI/DispatcherTimer.cs
Expand Up @@ -8,14 +8,24 @@ public class DispatcherTimer : IDispatcherTimer
{
private Timer timer;

#if WINDOWS_UWP
/// <summary>
/// Initializes a new instance of the <see cref="DispatcherTimer"/> class with the CoreApplication.MainView.CoreWindow.Dispatcher.
/// </summary>
public DispatcherTimer() : this(Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="DispatcherTimer"/> class.
/// </summary>
public DispatcherTimer()
public DispatcherTimer(Windows.UI.Core.CoreDispatcher dispatcher)
{
this.Dispatcher = dispatcher;
}

#if __IOS__
public Windows.UI.Core.CoreDispatcher Dispatcher { get; set; }
#elif __IOS__
/// <summary>
/// Initializes a new instance of the <see cref="DispatcherTimer"/> class.
/// </summary>
Expand Down Expand Up @@ -83,7 +93,7 @@ private void UpdateTick()
this.Activity.RunOnUiThread(() =>
{
#elif WINDOWS_UWP
Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
#endif
Tick?.Invoke(this, null);
Expand Down

0 comments on commit 6746f84

Please sign in to comment.