-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improvements to DispatcherQueueTimer.Debounce extension #569
Conversation
TODO: Still have the opposite scenario of Trailing to leading which is broken to fix.
…ing to Leading for a DispatcherQueueTimer
…Table 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.
312ae0f
to
7985456
Compare
…r.Debounce method to the docs
…event of the DispatcherQueueTimer when using Debounce Behavior should be well defined now. In the future, we could define a 'repeating' behavior, if we think it'd be useful (not sure of the specific scenario), but to do so, I would recommend we encorporate it at the end of the current signature and make false by default: public static void Debounce(this DispatcherQueueTimer timer, Action action, TimeSpan interval, bool immediate = false, bool repeat = false) I would imagine, this would do something like continually pulse the Action/Tick event but when additional requests are received that it would disrupt that periodic pattern somehow based on the debounce configuration (trailing/leading)?
Alright, I've added more info to the docs, and added custom We've fixed that by explicitly setting From 26ac1f8:
I'm not exactly sure how leading/trailing would effect/interrupt the timer in that fashion though... so future problem. Intent here of this PR was to make the timer work as well as intended and support the ability to dynamically change the leading/trailing edge, as well as provide better docs, samples, and clarification of its behavior and ensure we have proper test. This PR can hopefully be a good guide for future improvements anyone would want to make in other areas of the Toolkit in bolstering existing API surfaces. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great updates, especially the tests! A few minor change suggestions, otherwise, LGTM.
components/Extensions/samples/DispatcherQueueTimerExtensions.md
Outdated
Show resolved
Hide resolved
components/Extensions/src/Dispatcher/DispatcherQueueTimerExtensions.cs
Outdated
Show resolved
Hide resolved
components/Extensions/tests/DispatcherQueueTimerExtensionTests.cs
Outdated
Show resolved
Hide resolved
components/Extensions/tests/DispatcherQueueTimerExtensionTests.cs
Outdated
Show resolved
Hide resolved
components/Extensions/tests/DispatcherQueueTimerExtensionTests.cs
Outdated
Show resolved
Hide resolved
components/Extensions/tests/DispatcherQueueTimerExtensionTests.cs
Outdated
Show resolved
Hide resolved
components/Extensions/tests/DispatcherQueueTimerExtensionTests.cs
Outdated
Show resolved
Hide resolved
components/Extensions/tests/DispatcherQueueTimerExtensionTests.cs
Outdated
Show resolved
Hide resolved
components/Extensions/tests/DispatcherQueueTimerExtensionTests.cs
Outdated
Show resolved
Hide resolved
…Thanks! Co-authored-by: Arlo <[email protected]>
Thanks @Arlodotexe! Added those in, and we'll 🤞 on tests again... Oh, just thinking, we unblocked our CI by pinning on .NET 8, so could it be the switch to .NET 9 where we saw improvements? Or did we not get a clean build there... just wondering if there was some configuration change in between where you were seeing more stability? |
@michael-hawker We started seeing consistent passing results in #493 after merging We hadn't updated to net9 there. it's not clear why the merged changes fixed the issue, or why it's started happening again. MSBuilld was recently updated in CI, that might be it? We tried pinning the msbuild version long ago like we recently did for dotnet, but it's not working anymore and we're using the latest image. |
Fixes #143 (among other things not filed)
This PR does a lot of clean-up for the Debounce function, it adds:
IsRepeating
on the timer to false during initialization. FYI @huynhsontung - This shouldn't effect your own registrations to theTick
method, if you're using Debounce, there should only be the one timer per Debounce, and yourTick
should be called whenever the Debounce fires.PR Type
What kind of change does this PR introduce?
What is the current behavior?
Switching from trailing to leading edge of Debounce wouldn't fire immediately.
Using Debounce would hold reference to DispatcherQueueTimer object.
What is the new behavior?
Switching from trailing to leading edge now fires immediately.
Using Debounce doesn't hold a reference to the DispatcherQueuTimer object
PR Checklist
Please check if your PR fulfills the following requirements:
Other information
Tick
handler as well in user code.IsRepeating
to false on the timer.IsRepeating
should be and remainfalse
.