加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – UWP后台任务错误

发布时间:2020-12-15 21:01:05 所属栏目:百科 来源:网络整理
导读:我想创建一个后台任务,它在应用程序启动时启动.为此我使用Application Trigger. MainPage.xaml.cs中 var trigger = new ApplicationTrigger(); BackgroundManagement.RegisterBackgroundTask("InternetBackgroundTask.InternetBackground","Internet",trigge
我想创建一个后台任务,它在应用程序启动时启动.为此我使用Application Trigger.

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;
    }

Mytask在另一个项目上

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.

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

解决方法

你的剪辑中有两件事并不明显:

您是否已在Package.appxmanifest中的“声明”下声明了后台任务?

第二个:什么项目类型是“InternetBackground.cs”?它应该是Windows运行时组件

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读