c# – Windows Phone 7 Mango(7.1) – 后台任务未重复调用

我正在使用后台任务在应用程序未运行时执行活动.下面是我应该每30分钟调用一次的示例代码,并将时间戳添加到Isolated Storage上的文件中.问题是,后台任务(OnInvoke事件)仅在我添加它时调用(ScheduledActionService.Add(periodicTask);).它不是每30分钟调用一次.

protected override void OnInvoke(ScheduledTask task)
{
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
    if (myIsolatedStorage.FileExists("testbg.txt"))
    {
        EditExistingFile("testbg.txt", DateTime.Now.ToString() + Environment.NewLine);
    }
    else
    {
        CreateNewFile("testbg.txt", DateTime.Now.ToString() + Environment.NewLine);
    }
}

NotifyComplete();
}

public static void StartBackgroundTask()
{
PeriodicTask periodicTask = new PeriodicTask("Project One Tasks");

// The description is required. This is the string that the user
// will see in the background services Settings page on the device.
periodicTask.Description = "Performs various activities related to Project One.";
periodicTask.ExpirationTime = DateTime.Now.AddDays(10);

// If the agent is already registered with the system,
// call the StopPeriodicAgent helper method.
if (ScheduledActionService.Find(periodicTask.Name) != null)
{
    StopBackgroundTask();
}

ScheduledActionService.Add(periodicTask);
}

编辑:

有一点我注意到,当我启动Periodic或ResourceIntensive Task时,我得到以下对话框:

适用于Windows Phone的Microsoft Visual Studio 2010 Express

与设备的远程连接已丢失.请验证设备连接并重新启动调试.

有人在调用任务时收到此消息吗?

最佳答案 Beta 2改变了这种行为.你有没有重新检查(并测试它芒果手机而不是模拟器)?

点赞