MessageBox.Show hangs

Fundamentals for Avalonia Forum

Posted 22 days ago by Michael Janulaitis - Corner Bowl Software
Avatar

Windows message box calls are all synchronous.  When attempting to port to Avalonia the MessageBox API breaks Windows compatibility thanks to an async call to display the message box.  The workaround should be to wait for the task to complete via GetAwaiter().GetResult() or .Result.  Both scenarios hang the application.  Here's the code I am using:

var result = MessageBox.Show(
question,
AboutViewModel.ProductName,
MessageBoxButtons.YesNo,
MessageBoxImage.Information
).Result;

Comments (2)

Posted 22 days ago by Michael Janulaitis - Corner Bowl Software
Avatar

After reviewing my code, virtually all of my message box questions are sitting in an async call except a few properties setters which can be re-worked.  Once I update my ViewModels to utilize the async calls, I will need to add async wrappers around my WPF calls.

Posted 22 days ago by Actipro Software Support - Cleveland, OH, USA
Avatar

You are correct.  The MessageBow.Show method is async in Avalonia to be consistent with the Window.Show method.  This is just a subtle difference between WPF and Avalonia and any call to MessageBox.Show should be awaited.


Actipro Software Support

Add Comment

Please log in to a validated account to post comments.