locked
Using BackgroundTask for real time application in windows phone RRS feed

  • Question

  • Hi, 

    We want to develop one real time chat kind of application where we want to use backgroundTask for running service in background all the time, foreground need to communicate with backgroundTask.

    Now the problem as per our requirement we need frequent communication from foreground UI to backgroundTask. But we don't find any appropriate method to do it as it is having only two functions call of progress and completed event. Can anyone give some information about how we can send multiple calls from both UI to background and backgound to UI.

    Tuesday, September 9, 2014 5:44 AM

Answers

  • The matter of foreground/background communication aside: you can not run a background task continuously. There are several triggers that will start a background task but they only get a little time alotted to run thereafter.

    You will unfortunately have to adapt your application architecture.

    • Proposed as answer by Dave SmitsMVP Wednesday, September 10, 2014 9:13 AM
    • Marked as answer by Leo (Apple) Yang Tuesday, September 23, 2014 2:59 AM
    Wednesday, September 10, 2014 7:52 AM

All replies

  • Hi,

    I would like to recommend you another way to create a real time chat app for WP. Here is a sample about this topic,

    # Windows Phone 8 Chat Application using SignalR

    http://code.msdn.microsoft.com/windowsapps/Windows-Phone-8-Chat-1fa5eccf

    Regards,

    Jimmy



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, September 10, 2014 2:06 AM
  • Thanks Jimmy for the answer.

    I have checked signalR, but it seems like we have to use there API for HTTP connection.

    But problem which we have is our chat API is already implemented in C,C++ source code for other mobile platform so we wanted to reuse all the APIs of it. So we wanted to make some kind of background service which will make sure that even if UI is not running background should run. And there should be way to communicate with foreground app from background when UI is in foreground for real time update from the service as well as from UI to background if need to update anything on the server.

    Can you please help us to identify any other way to achieve it, as i am new in wp development platform.

    Wednesday, September 10, 2014 6:21 AM
  • The matter of foreground/background communication aside: you can not run a background task continuously. There are several triggers that will start a background task but they only get a little time alotted to run thereafter.

    You will unfortunately have to adapt your application architecture.

    • Proposed as answer by Dave SmitsMVP Wednesday, September 10, 2014 9:13 AM
    • Marked as answer by Leo (Apple) Yang Tuesday, September 23, 2014 2:59 AM
    Wednesday, September 10, 2014 7:52 AM
  • Thanks for the reply.

    I am still confused then how the real time application we can develop with windows phone where background service is allowed to run only for little time. Only Geo-location application we can have always running in background.

    Because chat kind of application needs real time data not some kind of polling mechanism. If any one have some experience please share. 

    Wednesday, September 10, 2014 1:51 PM
  • Running all the time is simply banned due to battery consumption concerns. The way it's supposed to work is using Push Notifications. E.g. the messages are sent to your server which then initiates the system's push notification service. You can simply send a toast message or use the push notification as a trigger for a background task which could then fetch the message before displaying a toast to the user.

    The architecture works pretty well and only requires a single network connection on the device itself (to the push server). It doesn't work with existing protocols like IRC or SIP however.

    Wednesday, September 10, 2014 2:13 PM