Skip to content

Commit c2e3c52

Browse files
committed
Changed all DispatcherTimer to DispatcherQueueTimer.
1 parent 2352a46 commit c2e3c52

File tree

7 files changed

+36
-33
lines changed

7 files changed

+36
-33
lines changed

Microsoft.Toolkit.Uwp.DeveloperTools/FocusTracker/FocusTracker.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Linq;
88
using System.Text;
99
using System.Threading.Tasks;
10+
using Windows.System;
1011
using Windows.UI.Xaml;
1112
using Windows.UI.Xaml.Automation;
1213
using Windows.UI.Xaml.Controls;
@@ -45,7 +46,7 @@ private static void OnIsActiveChanged(DependencyObject d, DependencyPropertyChan
4546
}
4647
}
4748

48-
private DispatcherTimer updateTimer;
49+
private DispatcherQueueTimer updateTimer;
4950
private TextBlock controlName;
5051
private TextBlock controlType;
5152
private TextBlock controlAutomationName;
@@ -72,7 +73,7 @@ private void Start()
7273
{
7374
if (updateTimer == null)
7475
{
75-
updateTimer = new DispatcherTimer();
76+
updateTimer = DispatcherQueue.GetForCurrentThread().CreateTimer();
7677
updateTimer.Tick += UpdateTimer_Tick;
7778
}
7879

Microsoft.Toolkit.Uwp.Input.GazeInteraction/GazePointer.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Windows.Devices.Input.Preview;
1212
using Windows.Foundation;
1313
using Windows.Foundation.Collections;
14+
using Windows.System;
1415
using Windows.UI;
1516
using Windows.UI.Core;
1617
using Windows.UI.Xaml;
@@ -354,7 +355,7 @@ private GazePointer()
354355
_gazeCursor = new GazeCursor();
355356

356357
// timer that gets called back if there gaze samples haven't been received in a while
357-
_eyesOffTimer = new DispatcherTimer();
358+
_eyesOffTimer = DispatcherQueue.GetForCurrentThread().CreateTimer();
358359
_eyesOffTimer.Tick += OnEyesOff;
359360

360361
// provide a default of GAZE_IDLE_TIME microseconds to fire eyes off
@@ -860,7 +861,7 @@ private void OnDeviceRemoved(GazeDeviceWatcherPreview sender, GazeDeviceWatcherR
860861

861862
private readonly List<int> _roots = new List<int>();
862863

863-
private readonly DispatcherTimer _eyesOffTimer;
864+
private readonly DispatcherQueueTimer _eyesOffTimer;
864865

865866
private readonly GazeCursor _gazeCursor;
866867

Microsoft.Toolkit.Uwp.UI.Behaviors/Focus/FocusBehavior.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System;
66
using System.Collections.Generic;
77
using System.Linq;
8+
using Windows.System;
89
using Windows.UI.Xaml;
910
using Windows.UI.Xaml.Controls;
1011
using Windows.UI.Xaml.Markup;
@@ -39,7 +40,7 @@ public sealed class FocusBehavior : BehaviorBase<UIElement>
3940
typeof(FocusBehavior),
4041
new PropertyMetadata(TimeSpan.FromMilliseconds(100)));
4142

42-
private DispatcherTimer _timer;
43+
private DispatcherQueueTimer _timer;
4344

4445
/// <summary>
4546
/// Initializes a new instance of the <see cref="FocusBehavior"/> class.
@@ -120,10 +121,8 @@ private void ApplyFocus()
120121
// This allows us to handle the case where the controls are not loaded in the order we expect.
121122
if (_timer is null)
122123
{
123-
_timer = new DispatcherTimer
124-
{
125-
Interval = FocusEngagementTimeout,
126-
};
124+
_timer = DispatcherQueue.GetForCurrentThread().CreateTimer();
125+
_timer.Interval = FocusEngagementTimeout;
127126
_timer.Tick += OnEngagementTimerTick;
128127
_timer.Start();
129128
}

Microsoft.Toolkit.Uwp.UI.Controls.Core/RotatorTile/RotatorTile.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Collections;
77
using System.Collections.Specialized;
88
using Microsoft.Toolkit.Uwp.Helpers;
9+
using Windows.System;
910
using Windows.UI.Xaml;
1011
using Windows.UI.Xaml.Controls;
1112
using Windows.UI.Xaml.Media;
@@ -32,7 +33,7 @@ public partial class RotatorTile : Control
3233

3334
private static readonly Random Randomizer = new Random();
3435
private int _currentIndex = -1; // current index in the items displayed
35-
private DispatcherTimer _timer; // timer for triggering when to flip the content
36+
private DispatcherQueueTimer _timer; // timer for triggering when to flip the content
3637
private FrameworkElement _currentElement; // FrameworkElement holding a reference to the current element being display
3738
private FrameworkElement _nextElement; // FrameworkElement holding a reference to the next element being display
3839
private FrameworkElement _scroller; // Container Element that's being translated to animate from one item to the next
@@ -387,7 +388,8 @@ private void Start()
387388

388389
if (_timer == null)
389390
{
390-
_timer = new DispatcherTimer() { Interval = GetTileDuration() };
391+
_timer = DispatcherQueue.GetForCurrentThread().CreateTimer();
392+
_timer.Interval = GetTileDuration();
391393
_timer.Tick += Timer_Tick;
392394
}
393395

Microsoft.Toolkit.Uwp.UI.Controls.Core/TileControl/TileControl.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Threading;
1010
using System.Threading.Tasks;
1111
using Windows.Foundation;
12+
using Windows.System;
1213
using Windows.UI.Composition;
1314
using Windows.UI.Xaml;
1415
using Windows.UI.Xaml.Controls;
@@ -39,7 +40,7 @@ public partial class TileControl : ContentControl
3940

4041
private Size _imageSize = Size.Empty;
4142

42-
private DispatcherTimer _timerAnimation;
43+
private DispatcherQueueTimer _timerAnimation;
4344

4445
/// <summary>
4546
/// A ScrollViewer used for synchronized the move of the <see cref="TileControl"/>
@@ -609,7 +610,7 @@ private void InitializeAnimation()
609610
{
610611
if (_timerAnimation == null)
611612
{
612-
_timerAnimation = new DispatcherTimer();
613+
_timerAnimation = DispatcherQueue.GetForCurrentThread().CreateTimer();
613614
}
614615
else
615616
{

Microsoft.Toolkit.Uwp.UI.Controls.DataGrid/DataGrid/DataGrid.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ private enum ScrollBarsSeparatorVisualState
171171
private DataGridRow _focusedRow;
172172
private FrameworkElement _frozenColumnScrollBarSpacer;
173173
private bool _hasNoIndicatorStateStoryboardCompletedHandler;
174-
private DispatcherTimer _hideScrollBarsTimer;
174+
private DispatcherQueueTimer _hideScrollBarsTimer;
175175

176176
// the sum of the widths in pixels of the scrolling columns preceding
177177
// the first displayed scrolling column
@@ -6423,19 +6423,19 @@ private void HideScrollBarsAfterDelay()
64236423
{
64246424
if (!_keepScrollBarsShowing)
64256425
{
6426-
DispatcherTimer hideScrollBarsTimer = null;
6426+
DispatcherQueueTimer hideScrollBarsTimer = null;
64276427

64286428
if (_hideScrollBarsTimer != null)
64296429
{
64306430
hideScrollBarsTimer = _hideScrollBarsTimer;
6431-
if (hideScrollBarsTimer.IsEnabled)
6431+
if (hideScrollBarsTimer.IsRunning)
64326432
{
64336433
hideScrollBarsTimer.Stop();
64346434
}
64356435
}
64366436
else
64376437
{
6438-
hideScrollBarsTimer = new DispatcherTimer();
6438+
hideScrollBarsTimer = DispatcherQueue.GetForCurrentThread().CreateTimer();
64396439
hideScrollBarsTimer.Interval = TimeSpan.FromMilliseconds(DATAGRID_noScrollBarCountdownMs);
64406440
hideScrollBarsTimer.Tick += HideScrollBarsTimerTick;
64416441
_hideScrollBarsTimer = hideScrollBarsTimer;
@@ -8208,7 +8208,7 @@ private void ShowScrollBars()
82088208
}
82098209
else
82108210
{
8211-
if (_hideScrollBarsTimer != null && _hideScrollBarsTimer.IsEnabled)
8211+
if (_hideScrollBarsTimer != null && _hideScrollBarsTimer.IsRunning)
82128212
{
82138213
_hideScrollBarsTimer.Stop();
82148214
_hideScrollBarsTimer.Start();
@@ -8290,7 +8290,7 @@ private void ShowScrollBars()
82908290

82918291
private void StopHideScrollBarsTimer()
82928292
{
8293-
if (_hideScrollBarsTimer != null && _hideScrollBarsTimer.IsEnabled)
8293+
if (_hideScrollBarsTimer != null && _hideScrollBarsTimer.IsRunning)
82948294
{
82958295
_hideScrollBarsTimer.Stop();
82968296
}

Microsoft.Toolkit.Uwp.UI.Controls.Input/ColorPicker/ColorPicker.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Globalization;
99
using Microsoft.Toolkit.Uwp.Helpers;
1010
using Microsoft.Toolkit.Uwp.UI.Controls.ColorPickerConverters;
11+
using Windows.System;
1112
using Windows.UI;
1213
using Windows.UI.Xaml;
1314
using Windows.UI.Xaml.Controls;
@@ -74,7 +75,7 @@ public partial class ColorPicker : Windows.UI.Xaml.Controls.ColorPicker
7475
private HsvColor? savedHsvColor = null;
7576
private Color? savedHsvColorRgbEquivalent = null;
7677
private Color? updatedRgbColor = null;
77-
private DispatcherTimer dispatcherTimer = null;
78+
private DispatcherQueueTimer dispatcherQueueTimer = null;
7879

7980
private ColorSpectrum ColorSpectrumControl;
8081
private ColorPickerSlider ColorSpectrumAlphaSlider;
@@ -134,15 +135,15 @@ public ColorPicker()
134135

135136
this.ConnectCallbacks(true);
136137
this.SetDefaultPalette();
137-
this.StartDispatcherTimer();
138+
this.StartDispatcherQueueTimer();
138139
}
139140

140141
/// <summary>
141142
/// Finalizes an instance of the <see cref="ColorPicker"/> class.
142143
/// </summary>
143144
~ColorPicker()
144145
{
145-
this.StopDispatcherTimer();
146+
this.StopDispatcherQueueTimer();
146147
this.CustomPaletteColors.CollectionChanged -= CustomPaletteColors_CollectionChanged;
147148
}
148149

@@ -1068,29 +1069,27 @@ private void SetDefaultPalette()
10681069
*
10691070
***************************************************************************************/
10701071

1071-
private void StartDispatcherTimer()
1072+
private void StartDispatcherQueueTimer()
10721073
{
1073-
this.dispatcherTimer = new DispatcherTimer()
1074-
{
1075-
Interval = new TimeSpan(0, 0, 0, 0, ColorUpdateInterval)
1076-
};
1077-
this.dispatcherTimer.Tick += DispatcherTimer_Tick;
1078-
this.dispatcherTimer.Start();
1074+
this.dispatcherQueueTimer = DispatcherQueue.GetForCurrentThread().CreateTimer();
1075+
this.dispatcherQueueTimer.Interval = new TimeSpan(0, 0, 0, 0, ColorUpdateInterval);
1076+
this.dispatcherQueueTimer.Tick += DispatcherQueueTimer_Tick;
1077+
this.dispatcherQueueTimer.Start();
10791078

10801079
return;
10811080
}
10821081

1083-
private void StopDispatcherTimer()
1082+
private void StopDispatcherQueueTimer()
10841083
{
1085-
if (this.dispatcherTimer != null)
1084+
if (this.dispatcherQueueTimer != null)
10861085
{
1087-
this.dispatcherTimer.Stop();
1086+
this.dispatcherQueueTimer.Stop();
10881087
}
10891088

10901089
return;
10911090
}
10921091

1093-
private void DispatcherTimer_Tick(object sender, object e)
1092+
private void DispatcherQueueTimer_Tick(object sender, object e)
10941093
{
10951094
if (this.updatedRgbColor != null)
10961095
{

0 commit comments

Comments
 (0)