简体   繁体   English

如何在WP7中通过节电器关闭后打开计划任务代理?

[英]How to turn on the Scheduled Task Agent after it is off by battery saver in WP7?

I have added Scheduled Task Agent in my WP7 app to remind the periodically. 我在WP7应用程序中添加了Scheduled Task Agent以定期提醒。 While testing after 2-3 days the agent will be off and it won't turn back again even if i open the app and start the task again. 在2-3天后测试时,代理将关闭,即使我打开应用程序并再次启动任务,它也不会再次返回。 Below is what I have tried in my ScheduledTaskAgent: 以下是我在ScheduledTaskAgent中尝试过的内容:

protected override void OnInvoke(ScheduledTask task)
    {
        DateTime time = DateTime.Now;
        if (time.Hour > 6 && time.Hour < 23)
        {
            getContent();
            if (task.Name.Equals("PeriodicTaskDemo", StringComparison.OrdinalIgnoreCase))
            {
                ShellToast toast = new ShellToast();
                Mutex mutex = new Mutex(true, "ScheduledAgentData");
                mutex.WaitOne();
                IsolatedStorageSettings setting = IsolatedStorageSettings.ApplicationSettings;
                toast.Title = setting["ScheduledAgentData"].ToString();
                mutex.ReleaseMutex();
                toast.Content = "You are being notified!!";
                toast.Show();
            }
            NotifyComplete();
        }

    }

The battery saver won't disable you background task from starting again. 省电模式不会禁用后台任务再次启动。 The only reasons your agent was disabled: 禁用代理的唯一原因:

  • you have disabled it manually in background tasks settings 您已在后台任务设置中手动禁用它
  • it crashed in exception two times in a row 它连续两次在例外情况下坠毁
  • it exceeded the maximum running time several times in a row (~20s) 它连续几次超过最大运行时间(~20s)
  • it has used more memory than it was available (6MB memory cap on WP7, 11MB on WP8) 它使用的内存比现有的多(WP7上6MB内存,WP8上11MB)
  • when scheduling task, you also set the property for how long it should run, after this time it won't start again. 在调度任务时,您还要设置属性应该运行多长时间,此时它不会再次启动。 On WP7 background tasks stops running after 14 days automatically. 在WP7上,后台任务会在14天后自动停止运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM