locked
Share data between background task and main project? RRS feed

  • Question

  • I have a project where I am trying to implement geofencing using the background task. The user can specify a location and radius and his device will automatically mute while entering that geofence. I have created a customized class against which I created a database table and the values entered by user are stored in the database.

    I also wrote a function that returns a list of objects of the customized class. How can I pass this list to the background task?

    Wednesday, May 11, 2016 8:32 PM

Answers

  • Hi,

    What's not clear to me from the question is what type of 'database' you're referring to so it might help if you could clarify that.

    Putting that to one side, there are a few ways of doing this but the two main ones that come to mind would be to have your foreground application serialize the data into a file and then have your background task read that file.

    That would be using ApplicationData.Current.LocalFolder to store the file.

    If you wanted to, you could use a file-based-database (e.g. SQLite) to structure the contents of that file and maybe you're already doing just that?

    Another way would be to use settings to do the same thing - i.e. ApplicationData.Current.LocalSettings so you just store some simple name/value entries rather than having to create/read/write serialized data into a file.

    There are some other ways but those would be the main ones I'd look at.

    Hope that helps.

    Mike

    Wednesday, May 11, 2016 9:59 PM