简体   繁体   中英

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

I have written a UWP-App and it all works fine (in debug and release mode). I've packaged my app and installed it on a tablet on which windows 10 is installed (I develope on a windows 10 desktop pc), still no issues.
But now I want to run my app in assigned access mode (kiosk mode) on this tablet and suddenly out of nowhere my messageboxes doesn't show up anymore and an error appears.
Because I'm working with the mvvm pattern I've written a helper class for showing messageboxes so I don't need to use Windows.UI in my ViewModels:

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();
      });
   }
}

Error:

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()

I don't understand what is different while working with the assigned access in windows 10. Like mentioned above this error only appears when the app is running in the assigned access. In any other case all works fine (on the desktop pc and on the tablet).

So my question is:
Has anyone experienced a same issue while developing an app to run in the assigned access mode in windows 10?
Or has anyone an idea of how to solve this issue?

This may be crashing because you are using the MainView dispatcher, which will not work in a Windows 10 Assigned Access Mode app.

The recomendation is to use

CoreApplication.GetCurrentView().Dispatcher

instead of

CoreApplication.MainView.CoreWindow.Dispatcher

From " 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.

I recommend to use for kiosk mode is create kiosk user with shell replacing and autologin ( https://github.com/VoidVolker/kiosk ). It gives more control and in this case you are free from any other OS problems, features, crap and etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM