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)
{
foreach (var cur in BackgroundTaskRegistration.AllTasks)
{
if (cur.Value.Name == taskName)
{
return (BackgroundTaskRegistration)(cur.Value);
}
}
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