Search code examples
windows-runtimewindows-phone-8.1signalr.clientbackground-task

Create and maintain a SignalR connection in a WinRT Background Task


I currently have a Windows Phone app that connects to a SignalR service to receive notification data. The service pushes data to the phone, which the app accepts, process etc and it’s all working as expected.

However, I would like the app to continue to receive the notification data when the app is suspended and no longer in the foreground, and display the notification data as a toast message. From what I can see, the Background Task infrastructure offers no way to do this. I have access to a Suspending and Resuming event (using Prism) so here I could Register/Unregister my background task.

For the trigger, the only one that comes close to being relevant is the TimeTrigger, but this only has a freshness time of 15 minutes, so assuming I am recreating the connection in the background task, I would end up opening and then instantly closing the connection every 15 minutes which isn't what I want to do.

I could have an “infinite await” that just hangs until a timeout, but this doesn't feel like the right way to go (and the resource usage would be terrible).

Is there a way around this to achieve what I want to do?


Solution

  • No, Windows Phone apps cannot keep a channel open like this. If the goal is only for toasts then you can do the computation on the server and push a toast notification.

    Windows Store apps can do this with the ControlChannelTrigger class, but it is not supported on Windows Phone.