UWP background task error

I want to create a background task that starts when the application starts. For this, I use an 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 in another project

namespace InternetBackgroundTask
{
public sealed class InternetBackground : IBackgroundTask
{

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

Therefore, when I run my application, I have this error:

An exception was thrown in 0x776BE26B (KernelBase.dll) in backgroundTaskHost.exe: 0x04242420 (parameters: 0x31415927, 0x5DE30000, 0x003CED68).

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

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

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

I referenced my background job in my project, and I added my background job to my manifest

+4
1

, - :

"" Package.appxmanifest?

: "InternetBackground.cs"? Runtime Windows

0

Source: https://habr.com/ru/post/1649143/


All Articles