Windows phone 7 后台代理任务从未在Mango中执行
我有一个后台代理,我想在芒果执行更新生活瓷砖。 问题是它从未被执行过。 以下是我使用的代码:Windows phone 7 后台代理任务从未在Mango中执行,windows-phone-7,live-tile,Windows Phone 7,Live Tile,我有一个后台代理,我想在芒果执行更新生活瓷砖。 问题是它从未被执行过。 以下是我使用的代码: //start background agent PeriodicTask periodicTask = new PeriodicTask("BruceWpAgent"); periodicTask.Description = "BruceWp periodic live task"; periodicTask.ExpirationTime = System.DateTime.Now.AddDays
//start background agent
PeriodicTask periodicTask = new PeriodicTask("BruceWpAgent");
periodicTask.Description = "BruceWp periodic live task";
periodicTask.ExpirationTime = System.DateTime.Now.AddDays(10);
// If the agent is already registered with the system,
if (ScheduledActionService.Find(periodicTask.Name) != null)
{
ScheduledActionService.Remove("BruceWpAgent");
}
ScheduledActionService.Add(periodicTask);
我在使用后台作业但从未调用该任务的应用之间找到了我的应用名称。
我做错了什么?请查看此Windows Phone 7.5中的动手实验室,这应该涵盖它。此代码可能对您有所帮助
string periodicTaskName = "PeriodicAgent";
public bool agentsAreEnabled = true;
private void StartBackgroundAgent()
{
// Variable for tracking enabled status of background agents for this app.
agentsAreEnabled = true;
// Obtain a reference to the period task, if one exists
periodicTask = ScheduledActionService.Find(periodicTaskName) as PeriodicTask;
// If the task already exists and background agents are enabled for the
// application, you must remove the task and then add it again to update
// the schedule
if (periodicTask != null)
{
RemoveAgent(periodicTaskName);
}
periodicTask = new PeriodicTask(periodicTaskName);
// The description is required for periodic agents. This is the string that the user
// will see in the background services Settings page on the device.
periodicTask.Description = "Task to update the Economic times tile.";
// Place the call to Add in a try block in case the user has disabled agents
try
{
ScheduledActionService.Add(periodicTask);
// If debugging is enabled, use LaunchForTest to launch the agent in one minute.
ScheduledActionService.LaunchForTest(periodicTaskName, TimeSpan.FromMinutes(2));
}
catch (InvalidOperationException exception)
{
if (exception.Message.Contains("BNS Error: The action is disabled"))
{
MessageBox.Show("Background agents for this application have been disabled by the user.");
agentsAreEnabled = false;
}
}
}
您的代理分配到
periodicTask
?periodicTask periodicTask=新的periodicTask(“BruceWpAgent”);是错误吗?你如何验证它从未被调用?而不仅仅是任务代码中的错误?你能确认一下你的代理人的名字吗?