You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Switch Debounce DispatcherQueueTimer extension to use ConditionalWeakTable
This prevents capture holding onto the timer for garbage collection, validated with a unit test which fails with the ConcurrentDictionary, but succeeds with the ConditionalWeakTable
Because of the new Trailing/Leading behavior, we need the table in order to know if something was scheduled, otherwise we'd need reflection if we only stored the event handler, which wouldn't be AOT compatible.
/// <para>Used to debounce (rate-limit) an event. The action will be postponed and executed after the interval has elapsed. At the end of the interval, the function will be called with the arguments that were passed most recently to the debounced function. Useful for smoothing keyboard input, for instance.</para>
@@ -60,11 +62,11 @@ public static void Debounce(this DispatcherQueueTimer timer, Action action, Time
60
62
{
61
63
// If we have a _debounceInstance queued, then we were running in trailing mode,
62
64
// so if we now have the immediate flag, we should ignore this timer, and run immediately.
63
-
if(_debounceInstances.ContainsKey(timer))
65
+
if(_debounceInstances.TryGetValue(timer,outvar_))
64
66
{
65
67
timeout=false;
66
68
67
-
_debounceInstances.Remove(timer,outvar_);
69
+
_debounceInstances.Remove(timer);
68
70
}
69
71
70
72
// If we're in immediate mode then we only execute if the timer wasn't running beforehand
@@ -79,7 +81,7 @@ public static void Debounce(this DispatcherQueueTimer timer, Action action, Time
0 commit comments