简体   繁体   English

BackgroundTaskRegistration-值不在预期范围内

[英]BackgroundTaskRegistration - Value does not fall within the expected range

I'm having a persistent problem within my Windows 8 app. 我的Windows 8应用程序中一直存在问题。

I want to register a BackGroundTask like this: 我想这样注册一个BackGroundTask:

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... 我一直在寻找stackoverflow( 如这里 )和其他地方,但是我似乎找不到任何解决方案...

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? 有什么建议可能是什么问题?

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: 确保在Package.appxmanifest中使用正确的触发器注册了任务:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM