Search code examples
sql-server-cewindows-phonebackground-agent

How to communicate between a background agent and foreground app?


I have a background agent and a foreground app on Windows Phone Mango. (These are two different projects in the same solution.) When the background agent runs, it inserts records into a database that is accessible to the foreground app. How can I notify the foreground app that it should check the database for new rows?

I can't just have a static event in the data context class, because the background and foreground are two different threads, and static variables on a class are not shared across threads, right?

Do I just have to poll from the foreground?


Solution

  • How can I notify the foreground app that it should check the database for new rows?

    Considering that it's highly unlikely the background agent will run while the application is open in the foreground, you would just have to poll for changes when you open the application.

    Unless you use PUSH notifications, a background agent is only running every 30 minutes, and I find it unlikely that a user will keep your application open that long. And if you are using PUSH notifications, you can listen for them in your foreground application as well.