I want to know how can I declarate in the EntryPoint of a Declaration in the manifest file the location of the code to execute as a background task.
I have my code set in a folder called "Models" inside the project, But I don't know how to reffer to this code. Here you have a picture of it:
Just in case, here is my code inside the cs:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.ApplicationModel.Background;
using Windows.UI.Popups;
namespace Universal_in_C.Models
{
public sealed class ExampleBackgroundTask : IBackgroundTask
{
public async Task ExampleMethodAsync()
{
Debug.WriteLine("Done Exe");
var dialog = new MessageDialog("TESTING, TESTING LIKE THERE IS NO TOMORROW.");
await dialog.ShowAsync();
}
public async void Run(IBackgroundTaskInstance taskInstance)
{
BackgroundTaskDeferral _deferral = taskInstance.GetDeferral();
await ExampleMethodAsync();
_deferral.Complete();
}
}
}
And how I call it(I know that I need to change the entry here too);
private void button6_Click(object sender, RoutedEventArgs e)
{
var taskRegistered = false;
var exampleTaskName = "BackgroundTask";
foreach (var task in BackgroundTaskRegistration.AllTasks)
{
if (task.Value.Name == exampleTaskName)
{
taskRegistered = true;
break;
}
}
if (taskRegistered)
{
Debug.WriteLine("Already Exist");
}
else
{
var builder = new BackgroundTaskBuilder();
Debug.WriteLine("Started to Exist");
builder.Name = exampleTaskName;
builder.TaskEntryPoint = "exampleTaskName";
builder.SetTrigger(new SystemTrigger(SystemTriggerType.InternetAvailable, true));
builder.AddCondition(new SystemCondition(SystemConditionType.UserPresent));
builder.Register();
}
}
Thanks!