I want to display an alert dialog with two buttons when an error occurs. To my best knowledge, this is how to do it, using an Interaction property:
this.ViewModel.ConnectionError.RegisterHandler(interaction =>
{
var retry = await this.DisplayAlert("Connection failed", "Do you want to retry?", "RETRY", "ABORT");
if (retry)
interaction.SetOutput(DevicesViewModel.ErrorRecoveryOption.Retry);
else
interaction.SetOutput(DevicesViewModel.ErrorRecoveryOption.Abort);
});
The issue is that the exception is thrown inside a thread in a third-party library. DisplayAlert has to be called in the main thread. I tried the following:
this.ViewModel.ConnectionError.RegisterHandler(interaction =>
{
RxApp.MainThreadScheduler.ScheduleAsync(interaction, async (scheduler, i, cancelationToken) =>
{
this.Log().Debug("ScheduleAsync");
var retry = await this.DisplayAlert("Connection failed", "Do you want to retry?", "RETRY", "ABORT");
if (retry)
i.SetOutput(DevicesViewModel.ErrorRecoveryOption.Retry);
else
i.SetOutput(DevicesViewModel.ErrorRecoveryOption.Abort);
return Disposable.Empty;
});
});
I can see the log message in the console but the dialog doesn't display and the app crashes inside the ReactiveUI.dll. What am I doing wrong?