title: how to run two background tasks periodically in wp8 apps?
body: <p>In my Windows Phone 8 apps, I have to tasks(LiveTiles and ToastNotifications). I want to run those tasks as a periodical background tasks. The Toast Notification task to be run once per day and my LiveTiles task to be run in every 10 minutes. While adding second Periodic task, It showing an error(BNS Error: The maximum number of ScheduledActions of this type have already been added). Any one let me know the answer if you  have a solution. Here I attached the code.</p>
  
  <p>App.xaml.cs:</p>
  
  <pre><code>    var LiveTilesName = "LiveTiles";
          var ToastNotificationsName = "ToastNotifications";
  
          PeriodicTask LiveTilesPeriodicTask = ScheduledActionService.Find(LiveTilesName) as PeriodicTask;
          PeriodicTask ToastNotificationPeriodicTask = ScheduledActionService.Find(ToastNotificationsName) as PeriodicTask;
  
          if (LiveTilesPeriodicTask != null)
              ScheduledActionService.Remove(LiveTilesName);
  
          if (ToastNotificationPeriodicTask != null)
              ScheduledActionService.Remove(ToastNotificationsName);
  
          LiveTilesPeriodicTask = new PeriodicTask(LiveTilesName) { Description = "Update Live Tiles." };
          ToastNotificationPeriodicTask = new PeriodicTask(ToastNotificationsName) { Description = "Toast Notifications" };
  
          try
          {
              ScheduledActionService.Add(LiveTilesPeriodicTask);
              ScheduledActionService.LaunchForTest(LiveTilesName, TimeSpan.FromSeconds(10));
  
              ScheduledActionService.Add(ToastNotificationPeriodicTask);
              ScheduledActionService.LaunchForTest(ToastNotificationsName, TimeSpan.FromSeconds(10));
  
          }
          catch (InvalidOperationException e) { }
  </code></pre>
  
  <p>SchedulerAgentTask Code: </p>
  
  <pre><code>    protected override void OnInvoke(ScheduledTask task)
      {
          //ScheduledActionService.LaunchForTest("ToastNotifications", TimeSpan.FromSeconds(30));
          if (task.Name == "ToastNotifications")
          {
              SendNotifications();                                
          }
          else if(task.Name == "LiveTiles")
          {
  
              UpdateTiles();                
              ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(30));
          }
  
          else{}
  
          NotifyComplete();
      }
  </code></pre>