I trying to implement a background task for a raw notification on wp8.1.
I read the documentation on MSDN and other internet resources.
My application is working with debugger attached. The raw message is processed if the app is in foreground, background and even if the lock screen is activated.
But, stopping the debugger session and calling the application directly on device, the raw message is processed if the application is in foreground only. Not in background and not on lock screen.
What I did:
Generated a project for my background task
public void Run(IBackgroundTaskInstance taskInstance)
based on some Microsoft examples
Set the entry in the app manifest file (declaration, pushnotification, set Instance)
Using the following code to create the background task and open the channel
BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync();
PushNotificationChannel newChannel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
string uri = newChannel.Uri;
rawChannel = newChannel;
rawChannel.PushNotificationReceived += OnPushNotificationReceived;
BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder();
PushNotificationTrigger trigger = new PushNotificationTrigger();
taskBuilder.SetTrigger(trigger);
taskBuilder.TaskEntryPoint = "BPRERAW.clsRaw";
taskBuilder.Name = "clsRaw";
BackgroundTaskRegistration task = taskBuilder.Register();
Putting a break point into the background class at startup the break point is not active. Setting the push notification trigger as described above the breakpoint is marked as active.
!! Testing the application within the debugger by receiving a raw message the breakpoint is not reached!! I spend hours on this, but did not find any solution.
So I startet a small test project only with the relevant code. After changing the trigger for the background task to a system trigger the task was available in the lifecycle dropdown. The breakpoint in the task class was hit.
Switching back to the push notification task the breakpoint was not hit. The raw background task is never visible in the lifecycle dropdown! I think this is the main problem.
Hopefully anybody has a hint or idea.
Thanks, Oliver
From MSDN site, you cannot debug BackgroundTask when use PushNotificationTrigger.
https://msdn.microsoft.com/en-us/library/windows/apps/jj542415.aspx