Skip to content
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

Fix: SnackbarPresenter might throw ObjectDisposedException, display problems. #1138

Open
wants to merge 1 commit into
base: development
Choose a base branch
from

Conversation

textGamex
Copy link

Pull request type

Please check the type of change your PR introduces:

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

@github-actions github-actions bot added controls Changes to the appearance or logic of custom controls. PR Pull request dotnet labels Jun 19, 2024
@textGamex textGamex changed the title Fix: SnackbarPresenter might throw ObjectDisposedException and display problems. Fix: SnackbarPresenter might throw ObjectDisposedException, display problems. Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
controls Changes to the appearance or logic of custom controls. dotnet PR Pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant