WPF UI provides the Fluent experience in your known and loved WPF framework. Intuitive design, themes, navigation and new immersive controls. All natively and effortlessly.
Please check the type of change your PR introduces:
[ ] Update
[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, renaming)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] Documentation content changes
What is the current behavior?
In a scenario where a SnackbarPresenter is utilized within a page that employs a singleton service and is treated as a NavigationViewItem, switching between NavigationViewItems can repeatedly invoke the OnUnloaded method. This sequence leads to the CancellationTokenSource being disposed via its Dispose method, followed by attempts to call Cancel method on the already-disposed object, consequently resulting in an ObjectDisposedException being thrown.
During the process of displaying a Snackbar, if the user navigates to another page, the Snackbar fails to dismiss properly.
The CancellationTokenSource will no longer be disposed within the OnUnloaded method; rather, its disposal will be deferred to the class's finalizer. Additionally, invoking the OnUnloaded method will promptly trigger the hiding of the Snackbar.
I'm unsure if there's a better approach to properly dispose the CancellationTokenSource, as relying on the finalizer could result in untimely disposal due to the inherent unpredictability of garbage collection.
Pull request type
Please check the type of change your PR introduces:
What is the current behavior?
In a scenario where a
SnackbarPresenter
is utilized within a page that employs a singleton service and is treated as aNavigationViewItem
, switching between NavigationViewItems can repeatedly invoke theOnUnloaded
method. This sequence leads to theCancellationTokenSource
being disposed via itsDispose
method, followed by attempts to callCancel
method on the already-disposed object, consequently resulting in anObjectDisposedException
being thrown.During the process of displaying a
Snackbar
, if the user navigates to another page, theSnackbar
fails to dismiss properly.Issue Number: Snackbar Presenter throws an error when it is unloaded. #951
What is the new behavior?
The
CancellationTokenSource
will no longer be disposed within theOnUnloaded
method; rather, its disposal will be deferred to the class's finalizer. Additionally, invoking theOnUnloaded
method will promptly trigger the hiding of theSnackbar
.I'm unsure if there's a better approach to properly dispose the
CancellationTokenSource
, as relying on the finalizer could result in untimely disposal due to the inherent unpredictability of garbage collection.