简体   繁体   English

UWP后台任务错误

[英]UWP Background Task Error

I want create a Background task which starts when the application starts. 我想创建一个后台任务,它在应用程序启动时启动。 For that I use Application Trigger. 为此我使用Application Trigger。

MainPage.xaml.cs MainPage.xaml.cs中

    var trigger = new ApplicationTrigger();
    BackgroundManagement.RegisterBackgroundTask("InternetBackgroundTask.InternetBackground", "Internet", trigger, null);
    await trigger.RequestAsync();

BackgroundManagement.cs 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;
    }

Mytask on another project Mytask在另一个项目上

namespace InternetBackgroundTask
{
public sealed class InternetBackground : IBackgroundTask
{

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

So when I launch my application I have this error : 所以当我启动我的应用程序时,我有这个错误:

Exception thrown at 0x776BE26B (KernelBase.dll) in backgroundTaskHost.exe: 0x04242420 (parameters: 0x31415927, 0x5DE30000, 0x003CED68). 在backgroundTaskHost.exe中的0x776BE26B(KernelBase.dll)抛出异常:0x04242420(参数:0x31415927,0x5DE30000,0x003CED68)。

Exception thrown at 0x776BE26B in backgroundTaskHost.exe: Microsoft C++ exception: EETypeLoadException at memory location 0x003CDF18. backgroundTaskHost.exe中的0x776BE26B抛出异常:Microsoft C ++异常:内存位置0x003CDF18处的EETypeLoadException。

Exception thrown at 0x776BE26B in backgroundTaskHost.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000. backgroundTaskHost.exe中的0x776BE26B抛出异常:Microsoft C ++异常:[rethrow]在内存位置0x00000000。

Exception thrown at 0x776BE26B in backgroundTaskHost.exe: Microsoft C++ exception: EETypeLoadException at memory location 0x003CDF18. backgroundTaskHost.exe中的0x776BE26B抛出异常:Microsoft C ++异常:内存位置0x003CDF18处的EETypeLoadException。

I've referenced my background Task in my project and I've added my background Task in my manifest 我在项目中引用了我的后台任务,并在清单中添加了后台任务

There are two things wich are not obvious from your snipped: 你的剪辑中有两件事并不明显:

Have you declared your background task under "Declarations" in your Package.appxmanifest? 您是否已在Package.appxmanifest中的“声明”下声明了后台任务?

And second: In what project type is "InternetBackground.cs"? 第二:什么项目类型是“InternetBackground.cs”? It should be a Windows Runtime Component 它应该是Windows运行时组件

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

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