WP8.1 / Background Task for Raw Notify / Debugger OK -> NOT on Device

762 Views Asked by At

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

1

There are 1 best solutions below

1
On BEST ANSWER

From MSDN site, you cannot debug BackgroundTask when use PushNotificationTrigger.

Trigger the background task using the suspend drop down menu available in the Debug Location toolbar. This drop down shows the names of the background tasks that can be activated by Visual Studio. For this to work, the background task must already be registered and it must still be waiting for the trigger. For example, if a background task was registered with a one-shot TimeTrigger and that trigger has already fired, launching the task through Visual Studio will have no effect.

Note Background tasks using the ControlChannelTrigger or PushNotificationTrigger, and background tasks using a SystemTrigger with the SmsReceived trigger type, cannot be activated in this manner.

https://msdn.microsoft.com/en-us/library/windows/apps/jj542415.aspx