Afcosta
Afcosta

Reputation: 31

BackgroundTaskRegistration - Value does not fall within the expected range

I'm having a persistent problem within my Windows 8 app.

I want to register a BackGroundTask like this:

private void CheckTaskRegistration()
{
    foreach (var task in BackgroundTaskRegistration.AllTasks)
    {
        Debug.WriteLine(task);
        if (task.Value.Name == "CheckConTask")
        {
            isTaskRegistered = true;
            break;
        }
    }

    if (isTaskRegistered)
    {
        Debug.WriteLine("debug1");
    }
    else if (!isTaskRegistered)
    {
        BackgroundTaskBuilder btb = new BackgroundTaskBuilder();
        btb.Name = "CheckConTask";
        btb.TaskEntryPoint = "Btasks.CheckConTask";

       BackgroundTaskRegistration task = btb.Register();
       Debug.WriteLine("debug2");
    }
}

Everytime that I run the code on Local Machine it gives me the following error:

"Value does not fall within the expected range."

I've been searching on stackoverflow (Like here) and everywhere but I can't seem to find any solution...

It is also hard to find any information about this error since it is so generic..

I've created a whole new project with sample code like this and nothing.

Any suggestions what the problem might is?

Upvotes: 3

Views: 1281

Answers (1)

Jan Tanis
Jan Tanis

Reputation: 33

Your task does not have a trigger set:

TimeTrigger trigger = new TimeTrigger(15, false);
BackgroundTaskBuilder builder = new BackgroundTaskBuilder();
builder.TaskEntryPoint = typeof(SubTask).FullName;
builder.SetTrigger(trigger);
builder.Register();

Make sure the task is registered with the correct trigger in Package.appxmanifest:

<Extension Category="windows.backgroundTasks" EntryPoint="xxx.SubTask">
      <BackgroundTasks>
        <Task Type="timer"/>
      </BackgroundTasks>
    </Extension>

Upvotes: 0

Related Questions