I am trying to implement Background Tasks in my project. So I added a Windows Runtime Component Project
and given reference to it from my main Windows Phone 8.1 silverlight project
. But When I calling the below function I am getting an exception
"A first chance exception of type 'System.Exception' occurred in mscorlib.ni.dll. Additional information: Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))"
// Applications must have lock screen privileges in order to receive raw notifications
BackgroundAccessStatus backgroundStatus = await BackgroundExecutionManager.RequestAccessAsync();
// Make sure the user allowed privileges
if (backgroundStatus != BackgroundAccessStatus.Denied && backgroundStatus != BackgroundAccessStatus.Unspecified)
{
OpenChannelAndRegisterTask();
}
else
{
// This event comes back in a background thread, so we need to move to the UI thread to access any UI elements
Dispatcher.BeginInvoke(() =>
{
Debug.WriteLine("Lock screen access is denied");
});
}
Why this happens? Later I create a sample Windows phone project and the above code is working fine. What will be the reason for this strange issue?
Please help me to resolve this issue if you have any clue about it.