/// <summary> /// Unregisters the background task. /// </summary> public static void Unregister() { try { // The background task builder IBackgroundTaskRegistration backgroundTaskRegistration = null; // Deregister SkycapMailSyncNowPeriodically if (SyncMailBackgroundTask.IsRegistered(out backgroundTaskRegistration)) { backgroundTaskRegistration.Unregister(true); LogFile.Instance.LogInformation("", "", "Unregistered Background Task."); } } catch (Exception ex) { LogFile.Instance.LogError("", "", ex.ToString()); } }
/// <summary> /// Registers the background task. /// </summary> public async static void Register() { try { // The background task builder IBackgroundTaskRegistration backgroundTaskRegistration = null; try { // Check if we have background access BackgroundAccessStatus backgroundAccessStatus = await BackgroundExecutionManager.RequestAccessAsync(); LogFile.Instance.LogInformation("", "", string.Format("Lock Screen Access: {0}.", backgroundAccessStatus)); } catch { LogFile.Instance.LogInformation("", "", "Lock Screen Access."); } // If SkycapMailSyncNowPeriodically is not registered if (!SyncMailBackgroundTask.IsRegistered(out backgroundTaskRegistration)) { // Register SkycapMailSyncNowPeriodically BackgroundTaskBuilder skycapMailSyncPeriodically = new BackgroundTaskBuilder(); skycapMailSyncPeriodically.Name = SkycapMailSyncTaskName; skycapMailSyncPeriodically.TaskEntryPoint = typeof(SyncMailBackgroundTask).FullName; skycapMailSyncPeriodically.SetTrigger(new TimeTrigger(15, false)); skycapMailSyncPeriodically.AddCondition(new SystemCondition(SystemConditionType.InternetAvailable)); skycapMailSyncPeriodically.Register(); LogFile.Instance.LogInformation("", "", "Registered Background Task."); } } catch (Exception ex) { LogFile.Instance.LogError("", "", ex.ToString()); } }