1

ライブ タイルを更新するために Mango で実行したいバックグラウンド エージェントがあります。問題は、実行されないことです。これが私が使用したコードです:

//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);

バックグラウンド ジョブを使用するアプリの間に自分のアプリ名を見つけましたが、タスクは呼び出されません。私は何を間違っていますか?

4

2 に答える 2

2

このコードはあなたを助けるかもしれません。

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;
            }
        }
    }
于 2011-12-13T04:31:19.033 に答える
1

Windows Phone 7.5 でアプリケーションにマルチタスキングを追加するためのハンズオン ラボを確認してください。

于 2011-12-01T11:56:32.140 に答える