c#-在Windows 10中以指定的访问模式运行应用程序时无法显示MessageBox

我已经编写了一个UWP-App,并且一切正常(在调试和发布模式下).我已经打包好应用程序并将其安装在装有Windows 10的平板电脑上(我是在Windows 10台式机上开发的),仍然没有问题.但是现在我想在此平板电脑上以分配的访问模...

我已经编写了一个UWP-App,并且一切正常(在调试和发布模式下).我已经打包好应用程序并将其安装在装有Windows 10的平板电脑上(我是在Windows 10台式机上开发的),仍然没有问题.
但是现在我想在此平板电脑上以分配的访问模式(信息亭模式)运行我的应用,突然我的消息框不再显示,并出现错误.
因为我正在使用mvvm模式,所以我编写了一个用于显示消息框的帮助程序类,因此不需要在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中使用分配的访问权限时有什么不同.如上所述,仅当应用程序在分配的访问权限中运行时,才会出现此错误.在任何其他情况下,它们都可以正常工作(在台式机和平板电脑上).

所以我的问题是:
在开发应用程序以在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.

本文标题为:c#-在Windows 10中以指定的访问模式运行应用程序时无法显示MessageBox

基础教程推荐