Search code examples
windows-phone-7windows-phone-7.1windows-phone-8windows-phone-7.1.1

Can we call the code of MainPage.xaml.cs file from ScheduledAgent.cs when OnInvoke method is fired?


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.


Solution

  • 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.