Skip to content

[BUG] UserStoppedTypingBehavior Command does not run on the MainThread #2590

Description

@aalsamoht

Is there an existing issue for this?

  • I have searched the existing issues

Did you read the "Reporting a bug" section on Contributing file?

Current Behavior

The Command is NOT executed on the MainThread.

<SearchBar.Behaviors>
  <toolkit:UserStoppedTypingBehavior
    BindingContext="{Binding Path=BindingContext, Source={x:Reference UserStoppedTypingSearchBar}, x:DataType=SearchBar}"
    Command="{Binding SearchCommand, Mode=OneTime}"
    StoppedTypingTimeThreshold="750"
    ShouldDismissKeyboardAutomatically="False">
  </toolkit:UserStoppedTypingBehavior>
</SearchBar.Behaviors>
[RelayCommand]
private void Search(string searchTerm)
{
  var mt = MainThread.IsMainThread;
  Debug.WriteLine($"Search: {searchTerm} - MainThread: {mt}");
  Console.WriteLine($"Search: {searchTerm} - MainThread: {mt}");
}

Expected Behavior

The Command is executed on the MainThread.

Steps To Reproduce

  1. Open and run solution from reproduction repository.
  2. Enter text in the search bar, wait for the Command to execute and check the output in Console or Debug - MainThread: False.

Link to public reproduction project repository

https://github.com/aalsamoht/MauiUserStoppedTypingBehavior

Environment

- .NET MAUI CommunityToolkit: 11.1.0
- OS: iOS & Android
- .NET MAUI: 9.0.202

Anything else?

https://github.com/CommunityToolkit/Maui/blob/main/src/CommunityToolkit.Maui/Behaviors/UserStoppedTypingBehavior.shared.cs#L133

This causes intermittent app crashes.

Activity

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions