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

C# Windows Phone 7 Mango(7.1)-后台任务未重复调用,c#,background,windows-phone-7,C#,Background,Windows Phone 7,我使用后台任务在应用程序未运行时执行活动。下面是我的示例代码,应该每30分钟调用一次,并将时间戳添加到独立存储上的文件中。问题是,后台任务(OnInvoke事件)仅在我添加它时调用(ScheduledActionService.Add(PeriodictTask);)。它不是每30分钟叫一次 protected override void OnInvoke(ScheduledTask task) { using (IsolatedStorageFile myIsolatedStorage = I

我使用后台任务在应用程序未运行时执行活动。下面是我的示例代码,应该每30分钟调用一次,并将时间戳添加到独立存储上的文件中。问题是,后台任务(OnInvoke事件)仅在我添加它时调用(ScheduledActionService.Add(PeriodictTask);)。它不是每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);
}
编辑:

我注意到,当我开始周期性或资源密集型任务时,会出现以下对话框:


适用于Windows Phone的Microsoft Visual Studio 2010 Express 与设备的远程连接已丢失。请验证设备连接并重新启动调试。 好啊
有人在调用任务时收到此消息吗

我在这里胡乱猜测,但也许您应该每次都从OnInvoke中重新添加任务,让任务决定是否需要后续的任务调用

您多久检查一次,以确认此功能正常运行?

30分钟不是保证需要的,可能会漂移10分钟。

Beta 2改变了这种行为。您是否重新检查过(并用芒果手机代替模拟器进行了测试)

调试时,您可以尝试在更短的时间内再次启动任务。虽然它不能解决问题,但您不需要等待半个小时来了解发生了什么

protected override void OnInvoke(ScheduledTask task)
{
    // using ...

#if DEBUG
    // If we're debugging, fire the task again
    string taskName = "Project One Tasks";
    ScheduledActionService.LaunchForTest(taskName, new TimeSpan(0, 0, 30));
#endif

     NotifyComplete();
}

我在官方文档中找不到这个。我无法获得Mango设备。我来自印度。如果我是来自印度的开发者,你知道如何获得Mango设备吗?如果你是注册开发者,你可以升级现有设备,但我猜,由于你来自印度,AppDev成员资格还不可用?我错了吗?你不需要芒果专用设备。如果你想通过我的网站联系我,我可以让你给我发送一个.xap在我的芒果设备上测试。非常感谢你的支持。我需要得到老板的许可。我会问你并让你知道。