1

I'm trying to use background agents to update live tiles every x minutes. I've seen that I can use a Background Agent to update a live tile. I would like to make a query on the SqlCE db used in my project and I would like to execute it in the OnInvoke event.

How can I access a function present in my main WP7 project from the Background Agent project (in the same solution)?

Heinrich Ulbricht
  • 10,064
  • 4
  • 54
  • 85
Cris
  • 12,124
  • 27
  • 92
  • 159

1 Answers1

3

You can create a shared Class Library Project to share code between your UI and the Background Agent. Add a new Class Library to your solution and put all shared code in there. Then reference it from your main project and the Agent project.

Heinrich Ulbricht
  • 10,064
  • 4
  • 54
  • 85
  • In this case do i have to move sqlce database file to the new class library project? – Cris Nov 07 '11 at 23:19
  • All classes involved with your database, yes. An alternative would be to add the source file to both projects, but the Class Library is the cleaner way in my opinion. – Heinrich Ulbricht Nov 07 '11 at 23:26
  • This is what I did: Client library with DB classes, my phone app and the background agent app. I referred to the client library dll file in the phone as well as the background app. What happened to me was that whatever that got stored in the DB thru the phone app was not visible to me in the background app. It was like phone app -> client library-DB and background app -> client library -> DB and I believe there were 2 instances of the client library maintaining its own database. I wanted the phone app to store something to the DB and the background app to query it. It never worked. – serverfaces Aug 15 '13 at 22:56
  • @user1112919 it could work, if you "reset the connection" - dispose the datacontext and reopen it again. – Alex Sorokoletov Jun 12 '14 at 07:46