【发布时间】:2015-06-26 16:39:09
【问题描述】:
我使用以下方法在 WinRT 中请求锁屏访问:
public async void RequestLockScreenAccess()
{
var status = BackgroundExecutionManager.GetAccessStatus();
if (status == BackgroundAccessStatus.Unspecified || status == BackgroundAccessStatus.Denied)
status = await BackgroundExecutionManager.RequestAccessAsync();
switch (status)
{
case BackgroundAccessStatus.AllowedWithAlwaysOnRealTimeConnectivity:
_mainInfo.NotifyUser = "This app is on the lock screen and has access to Always-On Real Time Connectivity.";
break;
case BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity:
_mainInfo.NotifyUser = "This app is on the lock screen and has access to Active Real Time Connectivity.";
break;
case BackgroundAccessStatus.Denied:
_mainInfo.NotifyUser = "This app is not on the lock screen.";
break;
case BackgroundAccessStatus.Unspecified:
_mainInfo.NotifyUser = "The user has not yet taken any action. This is the default setting and the app is not on the lock screen.";
break;
}
}
这会给我 2 个不同的错误。如果我在行前或行上放置断点
status = await BackgroundExecutionManager.RequestAccessAsync();
代码将执行,但抛出以下异常:
在 mscorlib.dll 中出现“System.Exception”类型的未处理异常 附加信息:未找到元素。 (来自 HRESULT 的异常:0x8002802B (TYPE_E_ELEMENTNOTFOUND))
正如我在另一篇文章中看到的,这是其他人知道的错误,不了解 Microsoft。如果我不在此行之前放置断点,则执行将挂起。我在这里做错了什么?
似乎如果我卸载我的应用程序,它可能会工作,但在重新运行后它最终会再次失败。
【问题讨论】:
标签: c# windows-8 windows-runtime