Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows phone 8 是否可以动态加载BackGroundAgent并使其工作?_Windows Phone 8_Background Agents - Fatal编程技术网

Windows phone 8 是否可以动态加载BackGroundAgent并使其工作?

Windows phone 8 是否可以动态加载BackGroundAgent并使其工作?,windows-phone-8,background-agents,Windows Phone 8,Background Agents,我有一个Windows phone 8应用程序,我需要有一个用于此应用程序的BackGroundAgent。我知道我们只需在主应用程序中添加后台代理项目的引用,就可以了。但我想通过Assembly.load()在主应用程序中动态加载它,并使其工作 public MainPage() { try { System.Reflection.Assembly.Load("BackGroundAgent");

我有一个Windows phone 8应用程序,我需要有一个用于此应用程序的BackGroundAgent。我知道我们只需在主应用程序中添加后台代理项目的引用,就可以了。但我想通过Assembly.load()在主应用程序中动态加载它,并使其工作

    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>


我不明白为什么它不起作用——但你为什么不试试呢?或者您是否尝试过并出现错误?我尝试过,可以看到Backround代理已部署,但OnInvoke()未在计划时间调用。它成功了!我的后台dll依赖于其他dll,这些dll也应该存在于XAP中并动态加载。