MessageBox.Avalonia icon indicating copy to clipboard operation
MessageBox.Avalonia copied to clipboard

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

Open StarRiver123 opened this issue 1 year ago • 3 comments

it seem that loop

StarRiver123 avatar Dec 24 '24 13:12 StarRiver123

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

levinit avatar Jan 05 '25 04:01 levinit

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();
}

Swellshinider avatar Feb 14 '25 22:02 Swellshinider

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

CreateLab avatar Feb 16 '25 09:02 CreateLab