gpt4 book ai didi

c# - UWP 后台任务错误

转载 作者:行者123 更新时间:2023-11-30 12:56:46 25 4
gpt4 key购买 nike

我想创建一个在应用程序启动时启动的后台任务。为此,我使用应用程序触发器。

MainPage.xaml.cs

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

后台管理.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.

我已经在我的项目中引用了我的后台任务,并且我已经在我的 list 中添加了我的后台任务

最佳答案

从您的截图中有两件事不明显:

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

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

关于c# - UWP 后台任务错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38586958/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com