Im having a issue with the Background Tasks in WP8.1
I have created a background task as a windows runtime component following this tutorial :
http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh977055.aspx
The problem is, i can't get my background task to run. It runs onNetworkChange. When i can to flight mode and back it is not firing. When i go to lifecycle events in the Debug Location toolbar it says No Background tasks. I have debugged the code that registers the background task and it is getting registered. I am also getting 'This breakpoint will not currently be hit. No symbols have been loaded for this document' which i think is causing the problem.
I have tried
- deleting the bin and obj folder and rebuilding.
- cleaning the project.
- trying to build the project from scratch.
- turning Just my code option off.
- tried doing the same thing on another machine, still nothing.
My code for registering
var taskRegistered = false;
var exampleTaskName = "UploadTask";
foreach (var task in BackgroundTaskRegistration.AllTasks)
{
if (task.Value.Name == exampleTaskName)
{
taskRegistered = true;
break;
}
}
if (!taskRegistered)
{
var builder = new BackgroundTaskBuilder();
builder.Name = exampleTaskName;
builder.TaskEntryPoint = "Tasks.Upload";
builder.SetTrigger(new SystemTrigger(SystemTriggerType.NetworkStateChange, false));
BackgroundTaskRegistration task = builder.Register();
}
package manifest file is as follows
<Extensions>
<Extension Category="windows.backgroundTasks" EntryPoint="Tasks.Upload">
<BackgroundTasks>
<Task Type="systemEvent" />
<m2:Task Type="deviceUse" />
</BackgroundTasks>
</Extension>
</Extensions>
My task looks like this :
namespace Tasks
{
public sealed class Upload : IBackgroundTask
{
public void Run(IBackgroundTaskInstance taskInstance)
{
Debug.WriteLine("Am i even getting here?");
}
}
}
Can anyone help as i've spent far too long getting this to work. Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…