0

I am using PeriodicTask and ofcourse it runs for every 30 mins.Can we call the code of MainPage.xaml.cs file from ScheduledAgent.cs when OnInvoke method is fired ? I want to resued the code written in one of the method of MainPage.xaml.cs.

If that is not possible can i connect to the internet everytime the OnInvoke() method is fired and fetch the data and display them as tiles/toast ? Any suggestions would be really appreciated.

krrishna
  • 2,050
  • 4
  • 47
  • 101

1 Answers1

1

You can't use the code from MainPage in your background agent, because your main project must reference the background agent's project. So adding an additional reference from the background agent to the main project would create a cyclic dependency.

But you can still share code between your main project and your background agent. Just create a third project, of type "class library", and reference it from both the main project and the background agent project. Then put the shared code in that additional project.

Kevin Gosse
  • 38,392
  • 3
  • 78
  • 94
  • That helps.I have few events and async calls to some web services and I want to call this code from Background agent. Does it interrupt the execution of this code if it doesn't get completed in 15 seconds? Actually this web service gets refreshed for every 30 to 45 seconds. Is there any way we can have a background agent running every time if I receive fresh/updated data from a web service? E.g. when a tennis match is going on the score refreshes very often. Is there any way we can show the latest score on tiles ? – krrishna Dec 02 '12 at 14:12
  • @krrishna You can't programmatically trigger the background agent, nor make it run for more than 15 seconds. Maybe you should consider using push notifications. – Kevin Gosse Dec 02 '12 at 14:15