Skip to content

Conversation

@ne0rrmatrix
Copy link
Member

Description of Change

Fixes a bug where you open and close multiple secondary windows in a Windows environment and have snackbar registered. This prevents the crash that occurs otherwise. This changes the check for Application.Current.Windows.Count from 1 to 0 in OnClosed method for builder Configuration lifecycle events.

Linked Issues

PR Checklist

  • Has a linked Issue, and the Issue has been approved(bug) or Championed (feature/proposal)
  • Has tests (if omitted, state reason in description)
  • Has samples (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard
  • Documentation created or updated: https://github.com/MicrosoftDocs/CommunityToolkit/pulls

Additional information

There was a previous attempt to fix this but it set window count to unregister at 1 and not zero. After verifying that when app exits it does call LifeCycle events for OnClosed during shutdown when Application.Current is not null and windows count is zero I created this PR to address the issue.

Copilot AI review requested due to automatic review settings June 20, 2025 20:25
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug in the Windows snackbar registration logic by adjusting the check for the number of windows open during the application shutdown.

  • Changed the condition from checking for 1 open window to checking for 0 open windows in the OnClosed method.
  • Ensures that notifications are unregistered only when there are no open windows, preventing crashes during app shutdown.
Comments suppressed due to low confidence (1)

src/CommunityToolkit.Maui/Options.cs:90

  • The condition has been correctly updated from a check against 1 to 0, which should ensure that snackbar notifications are unregistered only when no windows remain. Please verify that this logic aligns with the overall lifecycle management of window events during app shutdown.
						else if (Application.Current.Windows.Count is 0)

Copy link
Contributor

@bijington bijington left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ne0rrmatrix

@VladislavAntonyuk VladislavAntonyuk merged commit 195458f into CommunityToolkit:main Jul 4, 2025
11 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jul 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Crash on second window close when SnackBar enabled on Windows (still reproducible in v12.0.0)

3 participants