0

I've implemented a (for now) simple Background Agent in my Windows Phone 8 app. In the background agent, a WebRequest is made to update a stock list stored in XML in the IsolatedStorage. In other parts of the app, during debugging, I can see the currently logged in user; however, when the BackgroundAgent launches, the CurrentUser is null. At this point, shouldn't the CurrentUser be cached in the application? It seems to be cached for one part of the app (the main app) but uncached/unacceptable in others (the background agent).The current user seems to never be set in my Background Agent. I'm willing to provide more information, but does anyone know if this is a bug, or an implementation error?

PROBLEM: CurrentUser always set to null in BackgroundAgent. Are the sessions different in the BackgroundAgent from the main project (which is why it is never set)? Any help is appreciated.

Carlos
  • 105
  • 1
  • 9
  • 1
    Please show some code! also, nothing is "cached" between each execution of a Background Agent - if you want a session or data to persist, it's your job to write that code! Also, the Background Agent and Foreground App do not share state! – Neil Turner May 20 '14 at 13:48
  • I didn't post code because my question is more about limitations and application scopes. I think you may have answered my question (background agent and foreground don't share the same state). Using Parse.com as my backend, I logged my user in (documentation says the user is cached between session/saved to disk), which is why I was confused as to why the CurrentUser was always null. I suppose then my question is better posed; how can I access a User from the background agent? Storing their credentials seems incredibly unsafe. – Carlos May 20 '14 at 15:15

1 Answers1

1

Background Agents and Foreground Apps have no direct way of communicating as there is no guarantee that both will be running at the same time and they are separate processes.

The OS does not provide an API for communication so the two prefered methods are...

  1. Use a web service to sync to data from Foreground App to Background Agent
  2. Use Isolated Storage to share data between the Foreground App and Background Agent

In regards to credentials - there are methods available to encrypt the data in .NET, but for future reference, PasswordVault is available if you target WP8.1 (SL or XAML).

Community
  • 1
  • 1
Neil Turner
  • 2,712
  • 2
  • 18
  • 37