I use the following method to request lockscreen access in 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; } }
This may give me two different errors. If I put a breakpoint before or in line
status = await BackgroundExecutionManager.RequestAccessAsync();
the code will be executed, but throw the following exception:
An unhandled exception of type "System.Exception" occurred in mscorlib.dll Additional information: The item was not found. (Exception from HRESULT: 0x8002802B (TYPE_E_ELEMENTNOTFOUND))
As I read in another post, this is a bug known to others, I don't know about Microsoft. If I do not put a breakpoint in front of this line, execution will hang. What am I doing wrong here?
It seems that if I uninstall my application, it may work, but after some retries, it will eventually work again.
source share