wpfui icon indicating copy to clipboard operation
wpfui copied to clipboard

Fix: SnackbarPresenter might throw ObjectDisposedException, display problems.

Open textGamex opened this issue 1 year ago • 0 comments

Pull request type

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.

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 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.

textGamex avatar Jun 19 '24 17:06 textGamex