Files
win8phoneApp/CampusAppWP8/CampusAppWP8ScheduledTaskAgent/Utility/BackgroundTasks.cs
2013-09-17 13:48:37 +02:00

50 lines
1.4 KiB
C#

using CampusAppWP8ScheduledTaskAgent.Resources;
using Microsoft.Phone.Scheduler;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CampusAppWP8ScheduledTaskAgent.Utility
{
public class BackgroundTasks
{
public static void StartPerodicTask(string taskName, string taskDesc) {
BackgroundTasks.StopPerodicTask(taskName);
PeriodicTask periodicTask = new PeriodicTask(taskName);
// load description from localized strings
periodicTask.Description = taskDesc;
try
{
ScheduledActionService.Add(periodicTask);
//ScheduledActionService.LaunchForTest(taskName, TimeSpan.FromSeconds(10));
}
catch (Exception e)
{
Logger.LogException(e);
}
}
public static void StopPerodicTask(string taskName)
{
PeriodicTask periodicTask = ScheduledActionService.Find(taskName) as PeriodicTask;
if (periodicTask != null)
{
try
{
ScheduledActionService.Remove(taskName);
}
catch (Exception e)
{
Logger.LogException(e);
}
}
}
}
}