Question

I have a simple xaml form which, when LoadState is called, enables a Dispatch Timer. When the dispatch timer fires, it checks a service for new items. If a new item meets a certain criteria, it adds the message to a local variable (which ends up being bound to a listview), and we use the ToastNotification framework to create a new toast. However, one thing I've noticed is that the ToastNotifications appear only to work when the app is focused (which, of course, defeats the point). I think this makes sense, in part, because my app is suspended when not focused.

However, I know my DispatchTimer is executed when the app is suspended, because I see the web requests firing off to the service. It must mean that my call to send the notification is deferred somehow. I guess conceptually, how do I get the toast notifications to execute if my app is suspended? I have read up on BackgroundTasks, but those only respond to system events. What I really want is for my app to poll for messages regardless of its suspended state, update the UI when it can and update notifications whether the app is supended or not.

Was it helpful?

Solution

Unfortunately the only reliable way to achieve your scenario is with a BackgroundTask, that you can run every 30 minutes. DispatcherTimer requires the UI thread, which will only run if your app has focus. If you are seeing web requests go out it may be due to some other anomaly, but effectively when your app is suspended no further user code is guaranteed to run - including popping a toast.

OTHER TIPS

It sounds like you might be looking for something more like push notifications. Would these work for you? You could use them to display toast notifications, update your live tile etc.

Notification Platform Development on Windows

Mobile Push Notifications to Any Client with Azure Notification Hubs

Get started with push notifications in Mobile Services

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top