Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

It can not click when box.ShowAsync().Result; #200

Open
StarRiver123 opened this issue Dec 24, 2024 · 3 comments
Open

It can not click when box.ShowAsync().Result; #200

StarRiver123 opened this issue Dec 24, 2024 · 3 comments

Comments

@StarRiver123
Copy link

it seem that loop

@levinit
Copy link

levinit commented Jan 5, 2025

Any more description? Do you call it in an override window OnClosing event handler function?

@Swellshinider
Copy link

I think i found his problem:

I've setup a simple button in my main window:

<Button
	Width="32"
	Height="32"
	Cursor="Hand"
	HorizontalAlignment="Stretch"
	Click="Button_Click">
</Button>
private void Button_Click(object? sender, RoutedEventArgs e)
{
    var box = MessageBoxManager
      .GetMessageBoxStandard("Caption", "Are you sure you would like to delete appender_replace_page_1?",
          ButtonEnum.YesNo);
    _ = box.ShowAsync().Result; // <- Issue
}

Issue:

When the button is clicked, the application thread gets blocked.

Observed Behavior:

  • The message box becomes unresponsive.
  • The main window also becomes unclickable.
  • The application is effectively frozen.

Image

Image

Using async with await seems to resolve the problem

private async void Button_PlayStopClick(object? sender, RoutedEventArgs e)
{
    var box = MessageBoxManager
      .GetMessageBoxStandard("Caption", "Are you sure you would like to delete appender_replace_page_1?",
          ButtonEnum.YesNo);
    _ = await box.ShowAsync();
}

@CreateLab
Copy link
Member

That's typical "feature" of gui frameworks
https://blog.stephencleary.com/2012/07/dont-block-on-async-code.html

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants