public static async Task<IBackgroundTaskRegistration> GetOrRegisterHceBackgroundTask(string bgTaskName, string taskEntryPoint, SmartCardTriggerType triggerType) { try { // Check if there's an existing background task already registered var bgTask = (from t in BackgroundTaskRegistration.AllTasks where t.Value.Name.Equals(bgTaskName) select t.Value).SingleOrDefault(); if (bgTask != null) { LogMessage("Background task already registered", NotifyType.StatusMessage); } else { if (!(await DoBackgroundRequestAccess())) { LogMessage("Background task access denied, task won't fire", NotifyType.ErrorMessage); throw new Exception("Failed to get background access"); } var taskBuilder = new BackgroundTaskBuilder(); taskBuilder.Name = bgTaskName; taskBuilder.TaskEntryPoint = taskEntryPoint; taskBuilder.SetTrigger(new SmartCardTrigger(triggerType)); bgTask = taskBuilder.Register(); LogMessage("Background task registered", NotifyType.StatusMessage); } bgTask.Completed += BgTask_Completed; bgTask.Progress += BgTask_Progress; return bgTask; } catch (Exception ex) { LogMessage("Failed to register background task: " + ex.ToString(), NotifyType.StatusMessage); throw; } }
public static async Task <IBackgroundTaskRegistration> GetOrRegisterHceBackgroundTask(string bgTaskName, string taskEntryPoint, SmartCardTriggerType triggerType) { try { // Check if there's an existing background task already registered var bgTask = (from t in BackgroundTaskRegistration.AllTasks where t.Value.Name.Equals(bgTaskName) select t.Value).SingleOrDefault(); if (bgTask != null) { LogMessage("Background task already registered", NotifyType.StatusMessage); } else { if (!(await DoBackgroundRequestAccess())) { LogMessage("Background task access denied, task won't fire", NotifyType.ErrorMessage); throw new Exception("Failed to get background access"); } var taskBuilder = new BackgroundTaskBuilder(); taskBuilder.Name = bgTaskName; taskBuilder.TaskEntryPoint = taskEntryPoint; taskBuilder.SetTrigger(new SmartCardTrigger(triggerType)); bgTask = taskBuilder.Register(); LogMessage("Background task registered", NotifyType.StatusMessage); } bgTask.Completed += BgTask_Completed; bgTask.Progress += BgTask_Progress; return(bgTask); } catch (Exception ex) { LogMessage("Failed to register background task: " + ex.ToString(), NotifyType.StatusMessage); throw; } }