public static async void RegisterNotifyTask() { try { var myTaskName = "NotifyTask"; var myTaskEntryPoint = "InstaNotifications.NotifyTask"; foreach (var cur in BackgroundTaskRegistration.AllTasks) { if (cur.Value.Name == myTaskName) { ExtensionHelper.Output($"{myTaskEntryPoint} already registered"); return; } } await BackgroundExecutionManager.RequestAccessAsync(); var taskBuilder = new BackgroundTaskBuilder { Name = myTaskName, TaskEntryPoint = myTaskEntryPoint }; taskBuilder.SetTrigger(new TimeTrigger(15, false)); var myFirstTask = taskBuilder.Register(); } catch { } }
public static void UnregisterNotifyTask() { try { var myTaskName = "NotifyTask"; var myTaskEntryPoint = "InstaNotifications.NotifyTask"; foreach (var cur in BackgroundTaskRegistration.AllTasks) { if (cur.Value.Name == myTaskName) { cur.Value.Unregister(true); ExtensionHelper.Output($"{myTaskEntryPoint} unregistered"); return; } } } catch { } }