C# Windows Phone 8.1智能卡应用程序后台任务崩溃
我有一个问题,我正试图解决一个多星期了,我只是不能解决它。 我正在尝试用nfc和智能卡制作一个非常简单的Windows Phone 8.1应用程序。 后来我尝试使用SmartCardEmulator类提供的智能卡仿真,但现在我只想有一个后台任务,在接近nfc标记/智能卡时执行这些操作。 对于这个问题,我做了一个完整的新项目,其中只包含基本内容。 当我按下按钮时,程序不断崩溃 开始时,我制作了一个空白的Windows Phone应用程序项目和一个Windows运行时组件,并将其添加到解决方案中。手机应用程序项目引用了Windows运行时组件项目 在MainPage.xaml中,我只放了一个按钮和一个文本框 类BackgroundTaskManager位于windows phone应用程序项目中,类TaskOne位于运行时组件项目中 在Package.appxmanifest文件中,我在声明中添加了后台任务,BackgroundTasks.TaskOne作为入口点,系统事件作为支持任务类型 在需求中,我启用了NFC 按下按钮时出现的错误如下:C# Windows Phone 8.1智能卡应用程序后台任务崩溃,c#,windows-phone-8,nfc,smartcard,background-task,C#,Windows Phone 8,Nfc,Smartcard,Background Task,我有一个问题,我正试图解决一个多星期了,我只是不能解决它。 我正在尝试用nfc和智能卡制作一个非常简单的Windows Phone 8.1应用程序。 后来我尝试使用SmartCardEmulator类提供的智能卡仿真,但现在我只想有一个后台任务,在接近nfc标记/智能卡时执行这些操作。 对于这个问题,我做了一个完整的新项目,其中只包含基本内容。 当我按下按钮时,程序不断崩溃 开始时,我制作了一个空白的Windows Phone应用程序项目和一个Windows运行时组件,并将其添加到解决方案中。手
A first chance exception of type 'System.ArgumentException' occurred in mscorlib.ni.dll
A first chance exception of type 'System.ArgumentException' occurred in mscorlib.ni.dll
A first chance exception of type 'System.UnauthorizedAccessException' occurred in SimpleNfcApp.exe
A first chance exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.ni.dll
A first chance exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.ni.dll
我尝试调试并将断点放在BackgroundTaskManager.cs中RegisterBackgroundTask方法的开头,然后在MainPage.xaml.cs中的doSomething结束时崩溃
以下是代码:
MainPage.xaml.cs
BackgroundTaskManager.cs
有人知道我做错了什么吗?
谢谢你的阅读。
格里兹,斯基皮
编辑:
我在MainPage.xaml.cs中的doSomething方法周围添加了一个try-catch块,并得到了一条新的更明显的错误消息
A first chance exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.ni.dll
System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
at Windows.ApplicationModel.Background.BackgroundTaskBuilder.Register()
at SimpleNfcApp.BackgroundTaskManager.<RegisterBackgroundTask>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at SimpleNfcApp.MainPage.<startTask>d__0.MoveNext() Second exception caught.
你有错误代码吗
var settings = ApplicationData.Current.LocalSettings;
settings.Values.Remove(taskName);
ApplicationData.Current.LocalSettings-对此文件的访问被拒绝
namespace BackgroundTasks
{
public sealed class TaskOne
{
IBackgroundTaskInstance _taskInstance;
BackgroundTaskDeferral _deferral;
public async void Run(IBackgroundTaskInstance taskInstance)
{
_taskInstance = taskInstance;
_deferral = taskInstance.GetDeferral();
int x;
x = 2 + 2;
_deferral.Complete();
}
}
}
A first chance exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.ni.dll
System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
at Windows.ApplicationModel.Background.BackgroundTaskBuilder.Register()
at SimpleNfcApp.BackgroundTaskManager.<RegisterBackgroundTask>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at SimpleNfcApp.MainPage.<startTask>d__0.MoveNext() Second exception caught.
//var trigger = new SmartCardTrigger(SmartCardTriggerType.EmulatorNearFieldEntry);
var trigger = new SystemTrigger(SystemTriggerType.ServicingComplete, false);
var settings = ApplicationData.Current.LocalSettings;
settings.Values.Remove(taskName);