我使用以下方法在 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。如果我不在此行之前放置断点,则执行将挂起。我在这里做错了什么?
似乎如果我卸载我的应用程序,它可能会工作,但在重新运行后它最终会再次失败。