Skip to content

Commit a3f4ce4

Browse files
Merge branch 'master' into sample-app-updates
2 parents a022a85 + 1c7e0e4 commit a3f4ce4

File tree

14 files changed

+129
-112
lines changed

14 files changed

+129
-112
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.Animations/ConnectedAnimations/ConnectedAnimationHelper.cs

Lines changed: 13 additions & 10 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.Media.Animation;
@@ -149,17 +150,19 @@ void LoadedHandler(object s, RoutedEventArgs args)
149150
listAnimProperty.ListViewBase.ScrollIntoView(parameter);
150151

151152
// give time to the UI thread to scroll the list
152-
var t = listAnimProperty.ListViewBase.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
153-
{
154-
try
153+
var dispatcherQueue = DispatcherQueue.GetForCurrentThread();
154+
var t = dispatcherQueue.EnqueueAsync(
155+
async () =>
155156
{
156-
var success = await listAnimProperty.ListViewBase.TryStartConnectedAnimationAsync(connectedAnimation, parameter, listAnimProperty.ElementName);
157-
}
158-
catch (Exception)
159-
{
160-
connectedAnimation.Cancel();
161-
}
162-
});
157+
try
158+
{
159+
var success = await listAnimProperty.ListViewBase.TryStartConnectedAnimationAsync(connectedAnimation, parameter, listAnimProperty.ElementName);
160+
}
161+
catch (Exception)
162+
{
163+
connectedAnimation.Cancel();
164+
}
165+
}, DispatcherQueuePriority.Normal);
163166

164167
animationHandled = true;
165168
}

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: 8 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;
@@ -7958,6 +7958,7 @@ private void ResetValidationStatus()
79587958
int editingRowSlot = this.EditingRow.Slot;
79597959

79607960
InvalidateMeasure();
7961+
// TODO: Move to DispatcherQueue when FEATURE_VALIDATION_SUMMARY is enabled
79617962
this.Dispatcher.BeginInvoke(() =>
79627963
{
79637964
// It's possible that the DataContext or ItemsSource has changed by the time we reach this code,
@@ -8207,7 +8208,7 @@ private void ShowScrollBars()
82078208
}
82088209
else
82098210
{
8210-
if (_hideScrollBarsTimer != null && _hideScrollBarsTimer.IsEnabled)
8211+
if (_hideScrollBarsTimer != null && _hideScrollBarsTimer.IsRunning)
82118212
{
82128213
_hideScrollBarsTimer.Stop();
82138214
_hideScrollBarsTimer.Start();
@@ -8289,7 +8290,7 @@ private void ShowScrollBars()
82898290

82908291
private void StopHideScrollBarsTimer()
82918292
{
8292-
if (_hideScrollBarsTimer != null && _hideScrollBarsTimer.IsEnabled)
8293+
if (_hideScrollBarsTimer != null && _hideScrollBarsTimer.IsRunning)
82938294
{
82948295
_hideScrollBarsTimer.Stop();
82958296
}
@@ -8762,6 +8763,7 @@ private void UpdateValidationResults(List<ValidationResult> newValidationResults
87628763
// If the number of errors has changed, then the ValidationSummary will be a different size,
87638764
// and we need to delay our call to ScrollSlotIntoView
87648765
this.InvalidateMeasure();
8766+
// TODO: Move to DispatcherQueue when FEATURE_VALIDATION_SUMMARY is enabled
87658767
this.Dispatcher.BeginInvoke(() =>
87668768
{
87678769
// It's possible that the DataContext or ItemsSource has changed by the time we reach this code,

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
{

Microsoft.Toolkit.Uwp.UI.Controls.Input/TokenizingTextBox/TokenizingTextBox.Selection.cs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System;
66
using System.Threading.Tasks;
77
using Windows.ApplicationModel.DataTransfer;
8-
using Windows.UI.Core;
8+
using Windows.System;
99
using Windows.UI.Xaml;
1010
using Windows.UI.Xaml.Controls;
1111
using Windows.UI.Xaml.Input;
@@ -136,28 +136,30 @@ private TokenizingTextBoxItem GetCurrentContainerItem()
136136

137137
internal void SelectAllTokensAndText()
138138
{
139-
_ = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
140-
{
141-
this.SelectAllSafe();
139+
var dispatcherQueue = DispatcherQueue.GetForCurrentThread();
140+
_ = dispatcherQueue.EnqueueAsync(
141+
() =>
142+
{
143+
this.SelectAllSafe();
142144

143-
// need to synchronize the select all and the focus behavior on the text box
144-
// because there is no way to identify that the focus has been set from this point
145-
// to avoid instantly clearing the selection of tokens
146-
PauseTokenClearOnFocus = true;
145+
// need to synchronize the select all and the focus behavior on the text box
146+
// because there is no way to identify that the focus has been set from this point
147+
// to avoid instantly clearing the selection of tokens
148+
PauseTokenClearOnFocus = true;
147149

148-
foreach (var item in Items)
149-
{
150-
if (item is ITokenStringContainer)
150+
foreach (var item in Items)
151151
{
152-
// grab any selected text
153-
var pretoken = ContainerFromItem(item) as TokenizingTextBoxItem;
154-
pretoken._autoSuggestTextBox.SelectionStart = 0;
155-
pretoken._autoSuggestTextBox.SelectionLength = pretoken._autoSuggestTextBox.Text.Length;
152+
if (item is ITokenStringContainer)
153+
{
154+
// grab any selected text
155+
var pretoken = ContainerFromItem(item) as TokenizingTextBoxItem;
156+
pretoken._autoSuggestTextBox.SelectionStart = 0;
157+
pretoken._autoSuggestTextBox.SelectionLength = pretoken._autoSuggestTextBox.Text.Length;
158+
}
156159
}
157-
}
158160

159-
(ContainerFromIndex(Items.Count - 1) as TokenizingTextBoxItem).Focus(FocusState.Programmatic);
160-
});
161+
(ContainerFromIndex(Items.Count - 1) as TokenizingTextBoxItem).Focus(FocusState.Programmatic);
162+
}, DispatcherQueuePriority.Normal);
161163
}
162164

163165
internal void DeselectAllTokensAndText(TokenizingTextBoxItem ignoreItem = null)

0 commit comments

Comments
 (0)