0

MessageDialog の ShowAsync() メソッドが散発的に失敗します。それが機能するかどうかは、ほとんどコイントスです。

private async Task CloseApp()
{
    MessageDialog restartMessage = new MessageDialog("Changes have made a restart necessary.", "App must Restart")
    restartMessage.Commands.Add(new UICommand("Close Application", (command) => { Application.Current.Exit(); }));

    await restartMessage.ShowAsync(); // Code breaks here
    Application.Current.Exit();
}

ほぼ同じ問題を抱えている別のユーザーを見つけましたが、そのページのすべての解決策でエラーの発生を防ぐことができません。彼らの解決策は次のようになります。

private async Task CloseApp()
{
    IAsyncOperation<IUICommand> asyncCommand = null;
    MessageDialog restartMessage = new MessageDialog("Changes have made a restart necessary.", "App must Restart")
    restartMessage.Commands.Add(new UICommand("Close Application", (command) => { Application.Current.Exit(); }));
    restartMessage.DefaultCommandIndex = 0;

    asyncCommand = restartMessage.ShowAsync(); // Code *still* breaks here
    Application.Current.Exit();
}

アップデート:

この問題は、別の MessageDialog によって呼び出されたメソッドで MessageDialog に対して ShowAsync() を実行しようとしたことが原因である可能性があります。同時に 2 つの MessageDialog を表示することはできないため、エラーがスローされます。

ディスパッチャーを使用する私のソリューション...実際にはまだ機能しませんが、とにかく気になります:

MessageDialog restartMessage = new MessageDialog("Changes have made a restart necessary.", "App must Restart");
restartMessage.Commands.Add(new UICommand("Close Application", (command) => { Application.Current.Exit(); }));

CoreDispatcher cD = Window.Current.CoreWindow.Dispatcher;
await cD.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
    await restartMessage.ShowAsync();
});
4

1 に答える 1

0

問題が MessageDialog 内から MessageDialog を開くことにあることがわかったら、ここに実装されているソリューションを使用できました。

MessageDialog ShowAsync が 2 番目のダイアログで accessdenied 例外をスローする

于 2016-07-06T18:43:42.193 に答える