当应用 运行 在 windows 10 中处于指定访问模式时无法显示 MessageBox

Can't show MessageBox while app is running in assigned access mode in windows 10

我写了一个 UWP-App 并且一切正常(在调试和发布模式下)。我已经打包了我的应用程序并将其安装在安装了 windows 10 的平板电脑上(我在 windows 10 台式电脑上开发),仍然没有问题。
但是现在我想 运行 我的应用程序在这台平板电脑上处于分配的访问模式(kiosk 模式),突然间我的消息框不再显示,并且出现错误。
因为我正在使用 mvvm 模式,所以我写了一个助手 class 来显示消息框,所以我不需要在我的 ViewModels 中使用 Windows.UI

public class UserNotificationService : IUserNotificationService
{
   public async Task ShowMessageDialogAsync(string message, string title = null)
   {
      MessageDialog messageDialog = title == null ? new MessageDialog(message) : new MessageDialog(message, title);
      await ShowAsync(messageDialog);
   }

   // This method throws an error
   private async Task ShowAsync(MessageDialog msgDialog)
   {
      // I've to do it like this because otherwise it won't work because I'm working on a different thread while calling this method
      await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.N‌​ormal, async () => {
         await msgDialog.ShowAsync();
      });
   }
}

错误:

A COM call to an ASTA was blocked because the call chain originated in or passed through another ASTA. This call pattern is deadlock-prone and disallowed by apartment call control.

A COM call (IID: {638BB2DB-451D-4661-B099-414F34FFB9F1}, method index: 6) to an ASTA (thread 6992) was blocked because the call chain originated in or passed through another ASTA (thread 7188). This call pattern is deadlock-prone and disallowed by apartment call control. at: at Windows.ApplicationModel.Core.CoreApplicationView.get_CoreWindow()

我不明白在 windows 10 中使用分配的访问权限时有什么不同。如上所述,只有当应用程序在分配的访问权限中 运行ning 时才会出现此错误。在任何其他情况下一切正常(在台式电脑和平板电脑上)。

所以我的问题是:
在 windows 10 中以分配的访问模式为 运行 开发应用程序时,是否有人遇到过同样的问题?
或者有人知道如何解决这个问题吗?

这可能会崩溃,因为您正在使用 MainView 调度程序,它在 Windows 10 分配的访问模式应用程序中不起作用。

推荐使用

CoreApplication.GetCurrentView().Dispatcher

而不是

CoreApplication.MainView.CoreWindow.Dispatcher

来自“Kiosk apps for assigned access: Best Practices

Each view or window has its own dispatcher. In assigned access mode, you should not use the MainView dispatcher, instead you should use the CurrentView dispatcher.