我已经编写了一个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


基础教程推荐
- c#中将uint值转换成int的实例方法 2023-01-27
- .net core 和 WPF 开发升讯威在线客服系统【私有化部署免费版】发布 2023-09-27
- 大家应该掌握的多线程编程 2022-12-05
- Linux服务器部署.Net Core笔记:五、安装Nginx 2023-09-26
- C#单线程和多线程的端口扫描器应用比较详解 2023-06-27
- C# WPF 父控件通过使用可视化树找到子控件的示例代码 2022-12-31
- Unity学习之FSM有限状态机 2023-04-21
- C#机房重构之sql语句及错误集锦 2023-11-10
- C#高效比较两个DataTable数据差异化的方法实现 2023-06-08
- C#字符串内存驻留机制分析 2023-05-16