0
votes

I am using the background task for a various features in the application. No where in the MSDN documentation, i see how long it runs.

For example in windows phone 8 sdk, periodic agents used to run for 25 seconds. is there a specific amount that the background task runs for ?

StorageFolder folder = KnownFolders.PicturesLibrary;
StorageFile TimeLogFile = await folder.CreateFileAsync("TimeLog.txt", CreationCollisionOption.OpenIfExists);

await Windows.Storage.FileIO.AppendTextAsync(TimeLogFile, "Start Logging " + DateTime.Now.ToString() + Environment.NewLine);
await Windows.Storage.FileIO.AppendTextAsync(TimeLogFile, "Beginning of Background Task " + DateTime.Now.ToString() + Environment.NewLine);

for (int i=0;i<100000;i++)
{
    await Windows.Storage.FileIO.AppendTextAsync(TimeLogFile, "During Background Task Execution " + DateTime.Now.ToString() + Environment.NewLine);
    Debug.WriteLine(i);
}
await Windows.Storage.FileIO.AppendTextAsync(TimeLogFile, "End Logging " + DateTime.Now.ToString() + Environment.NewLine);
1

1 Answers

0
votes

Here's the info you're looking for: http://msdn.microsoft.com/en-us/library/windows/apps/xaml/Hh977056(v=win.10).aspx.

Basically, a background task can only use the CPU for 2 seconds each time it's started. It can however be active for a longer period, if it doesn't do CPU intensive work. If you await something slow that does not use the CPU too much, you can get to several minutes of execution.