Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Rapid change of selected tab results in crash on Windows#32865

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
sheiksyedm wants to merge2 commits intodotnet:main
base:main
Choose a base branch
Loading
fromsheiksyedm:fix_32824

Conversation

@sheiksyedm
Copy link
Contributor

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you couldtest the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Root Cause

When users rapidly switch tabs in TabbedPage on Windows, concurrent navigation operations cause a crash:
Stack trace shows crash at line 299 (UpdateCurrentPageContent):

WinRT.Runtime.dll!WinRT.ExceptionHelpers.ThrowExceptionForHR(int hr) Microsoft.W
inUI.dll!Microsoft.UI.Xaml.Controls.ContentPresenter.Content.set(object value) M
icrosoft.Maui.Controls.dll!Microsoft.Maui.Controls.TabbedPage.UpdateCurrentPageC
ontent(WPage page) Line 299

The Problem Flow:
1. User rapidly clicks tabs (Tab 1 → Tab 2 → Tab 3)
2. First tab change callsNavigateToPageNavigationFrame.NavigateToType()
3. Navigation starts,OnNavigated event will fire when complete
4.Before first navigation completes, second tab change triggers anotherNavigateToPage
5. Second navigation also callsNavigateToType() → starts another navigation
6. BothOnNavigated events fire and try to setpresenter.Content
7.WinUI throws:ContentPresenter.Content cannot be modified during active navigation/layout operation

Additionally, settingSelectedItem inMapCurrentPage triggersSelectionChanged events that cause reentrant calls.

Solution

Implemented two guard flags to prevent race conditions:

  1. _isNavigating flag - Prevents overlapping navigation operations
    - Set before callingNavigateToType()
    - Checked at start ofNavigateToPage() - returns early if navigation in progress
    - Cleared inOnNavigated() finally block after content update completes

  2. _isUpdatingSelection flag - Prevents reentrant selection events
    - Set before updatingSelectedItem inMapCurrentPage
    - Checked at start ofOnSelectedMenuItemChanged - returns early if updating programmatically
    - Cleared in finally block after update completes

This ensures:
- Only one navigation operation runs at a time
- Subsequent rapid clicks are queued/ignored until current navigation completes
- No reentrant selection change events
- Safe cleanup via try-finally blocks

Fixes#32824

bronteq reacted with heart emoji
@dotnet-policy-servicedotnet-policy-servicebot added the partner/syncfusionIssues / PR's with Syncfusion collaboration labelNov 26, 2025
WFrame?_navigationFrame;
bool_connectedToHandler;
bool_isUpdatingSelection;
bool_isNavigating;

Choose a reason for hiding this comment

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

maybe these variables should be volatile?

volatile bool _isUpdatingSelection;volatile bool _isNavigating;

sheiksyedm reacted with thumbs up emoji

Choose a reason for hiding this comment

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

What is the reasoning behind using flags instead of some synchronization mechanism like a lock? I mean, if there is an operation that can not be run simultaneously, are the boolean flags sufficient? Or would it be better to use a Lock object and lock it? Or some kind of other synchronization like SemaphoreSlim?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@qjustfeelitp All operations run on the Windows UI thread:

 - OnSelectedMenuItemChanged - WinUI SelectionChanged event (UI thread) - NavigateToPage - Called from UI thread - OnNavigated - WinUI navigation event (UI thread) - MapCurrentPage - Handler update (UI thread)

WinUI guarantees these events are dispatched on the UI thread, so there's no concurrent multi-threaded access. The fix of adding flags prevents reentrant calls (the same thread calling again before completing).

Using synchronization primitives like lock or SemaphoreSlim would be overkill. Locking on the UI thread may cause deadlocks if any async operation awaits while holding the lock.

@sheiksyedm
Copy link
ContributorAuthor

/azp run MAUI-UITests-public

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

Copilot code reviewCopilotAwaiting requested review from CopilotCopilot will automatically review once the pull request is marked ready for review

2 more reviewers

@qjustfeelitpqjustfeelitpqjustfeelitp left review comments

@bronteqbronteqbronteq left review comments

Reviewers whose approvals may not affect merge requirements

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

area-controls-tabbedpageTabbedPagepartner/syncfusionIssues / PR's with Syncfusion collaborationplatform/windows

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Rapid change of selected tab results in crash on Windows.

3 participants

@sheiksyedm@qjustfeelitp@bronteq

[8]ページ先頭

©2009-2025 Movatter.jp