UWP 后台任务错误

5
我想创建一个在应用程序启动时就开始的后台任务。为此,我使用应用程序触发器。
MainPage.xaml.cs
    var trigger = new ApplicationTrigger();
    BackgroundManagement.RegisterBackgroundTask("InternetBackgroundTask.InternetBackground", "Internet", trigger, null);
    await trigger.RequestAsync();

BackgroundManagement.cs

    public static BackgroundTaskRegistration RegisterBackgroundTask(string taskEntryPoint,string taskName,IBackgroundTrigger trigger,IBackgroundCondition condition)
    {
        //
        // Check for existing registrations of this background task.
        //

        foreach (var cur in BackgroundTaskRegistration.AllTasks)
        {

            if (cur.Value.Name == taskName)
            {
                //
                // The task is already registered.
                //

                return (BackgroundTaskRegistration)(cur.Value);
            }
        }

        //
        // Register the background task.
        //

        var builder = new BackgroundTaskBuilder();

        builder.Name = taskName;
        builder.TaskEntryPoint = taskEntryPoint;
        builder.SetTrigger(trigger);
        

        if (condition != null)
        {

            builder.AddCondition(condition);
        }

        BackgroundTaskRegistration task = builder.Register();
       
        return task;
    }

我的另一个项目任务
namespace InternetBackgroundTask
{
public sealed class InternetBackground : IBackgroundTask
{

    public void Run(IBackgroundTaskInstance taskInstance)
    {
        System.Diagnostics.Debug.WriteLine("Run Background Task");
    }
}

当我启动我的应用程序时,出现以下错误:

Exception thrown at 0x776BE26B (KernelBase.dll) in backgroundTaskHost.exe: 0x04242420 (parameters: 0x31415927, 0x5DE30000, 0x003CED68).

Exception thrown at 0x776BE26B in backgroundTaskHost.exe: Microsoft C++ exception: EETypeLoadException at memory location 0x003CDF18.

Exception thrown at 0x776BE26B in backgroundTaskHost.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.

Exception thrown at 0x776BE26B in backgroundTaskHost.exe: Microsoft C++ exception: EETypeLoadException at memory location 0x003CDF18.

我已在我的项目中引用了后台任务,并在清单中添加了我的后台任务。

你在其他项目中引用了包含后台任务的 Windows 运行时组件吗? - TableCreek
是的,它被引用了。 - Guinard Arnaud
你有更改操作系统语言为英语的选项吗?我的法语太差了,无法将其翻译成英文等效词。这个错误消息对我来说听起来有点熟悉。在返回/创建新任务之前,您是否尝试过注销该任务? - TableCreek
我将错误信息从法语改为英语。是的,我尝试过注销,甚至卸载并重新安装我的应用程序。 - Guinard Arnaud
请将其以英文发送给我。 - TableCreek
显示剩余2条评论
1个回答

1

从你的代码片段中有两件事情并不明显:

你是否在Package.appxmanifest文件的“Declarations”下声明了后台任务?

其次: “InternetBackground.cs”所在的项目类型是什么?它应该是Windows Runtime组件。


第一个问题我认为是肯定的,它在他下面代码的最后一句话中。 - M. Pipal

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接