0

I have a Window phone 8 app and I need to have a BackGroundAgent for this app. I know that we can simply add the reference of background agent project in the main app and it works fine. but I want to load it dynamically in Main app through Assembly.Load() and make it work.

    public MainPage()
    {         
        try
        {
            System.Reflection.Assembly.Load("BackGroundAgent");
        }           
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);             
            return;
        }           
        StartPeriodicAgent();
    }

   private void StartPeriodicAgent()
    {
        periodicTask = ScheduledActionService.Find(periodicTaskName) as PeriodicTask;
        if (periodicTask != null)
        {
            ScheduledActionService.Remove(periodicTaskName);
        }

        periodicTask = new PeriodicTask(periodicTaskName);

        periodicTask.Description = "This demonstrates a periodic task.";

        try
        {
            ScheduledActionService.Add(periodicTask);
        }
        catch (SchedulerServiceException)
        {
        }
    }

WMAppManifest.xml

<Tasks>
  <DefaultTask Name="_default" NavigationPage="MainPage.xaml" ActivationPolicy="Resume" />
  <ExtendedTask Name="TombStoneBackGroundAgent">
    <BackgroundServiceAgent Name="TombStoneAgent" Source="BackGroundAgent.dll" Specifier="ScheduledTaskAgent" Type="BackGroundAgent.ScheduledAgent"/>
  </ExtendedTask>
</Tasks>
harshbodhi
  • 99
  • 9
  • 1
    I don't see why it wouldn't work - but why don't you just try it? Or have you tried and gotten an error? – Deeko Jun 07 '13 at 12:19
  • I tried it and I could see the Backround agent deployed but OnInvoke() is not called at Scheduled Time. – harshbodhi Jun 07 '13 at 12:20
  • It worked! My Background dll had a dependency on other dll which also should have been present in the XAP and loaded dynamically. – harshbodhi Jun 14 '13 at 08:36

0 Answers0