Windows phone 8.1 background task and foreground app communication

windows-8.1, windows-phone, windows-phone-8.1, windows-runtime

Solution

Here are some ideas (or info) about communication between the app and its background tasks.

You could use the Progress and Completed events of the IBackgroundTaskRegistration object. You can get that object using BackgroundTaskRegistration.AllTasks - this property returns the list of background tasks registered by the app. Each time the app runs, you'll have to subscribe to these events.

From the background task you can set the Progress property of the IBackgroundTaskInstance object to some UInt32 value, and the app will receive the event. Maybe you can encode what you need in that number. For example: 1 means that the task is initializing, 2 - the task is doing WorkA, and so on...

Both processess have access to the same files, so maybe you can use that for something.

Use Mutex to sync the execution of code between the two processes.

That's all I can think of right now. I hope it helps.

P.S. I haven't really tried those events, but they seem like they might be useful.

Problem

I am working on a Windows Phone 8.1 application which registers a background task timer trigger for hourly operation. So essentially, the background task wake up every 60 minutes and does some operation. My question is that, when the background task is in progress, if the user wakes up the application, is there a way that we can show the user what is happening in the background task process? I understand that they are two different processes. I am using a Silverlight 8.1 project for the foreground application and a managed windows runtime project for the background task. I am registering the background task using the silverlight application but i am in a dark now thinking about how to create a communication bridge between these two processes. Any clues ? Is this even possible ?

Original source