【发布时间】:2016-12-13 17:38:30
【问题描述】:
我想在发生错误时显示一个带有两个按钮的警报对话框。 据我所知,这是使用 Interaction 属性的方法:
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);
});
问题是异常是在第三方库的线程内引发的。 DisplayAlert 必须在主线程中调用。我尝试了以下方法:
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;
});
});
我可以在控制台中看到日志消息,但没有显示对话框,并且应用程序在 ReactiveUI.dll 内崩溃。 我做错了什么?
【问题讨论】:
标签: system.reactive reactiveui