public void Run(IBackgroundTaskInstance taskInstance) { var deferral = taskInstance.GetDeferral(); var httpClientService = new HttpClientService(); var dataService = new KursnaListaDataService(httpClientService); var settingsService = new SettingsService(); var dataContext = new KursnaListaDataContext(settingsService); var cacheService = new LocalStorageCacheService(dataContext); var repository = new KursnaListaRepository(dataService, cacheService); var cancelationTokenSource = new CancellationTokenSource(); repository.UpdateCacheAsync(cancelationTokenSource.Token).ContinueWith(_ => deferral.Complete(), cancelationTokenSource.Token); }
/// <summary> /// Agent that runs a scheduled task /// </summary> /// <param name="task"> /// The invoked task /// </param> /// <remarks> /// This method is called when a periodic or resource intensive task is invoked /// </remarks> protected async override void OnInvoke(ScheduledTask task) { //TODO: Add code to perform your task in background var httpClientService = new HttpClientService(); var dataService = new KursnaListaDataService(httpClientService); var cacheService = new PhoneStorageCacheService(); var repository = new KursnaListaRepository(dataService, cacheService); var cancelationTokenSource = new CancellationTokenSource(); await repository.UpdateCacheAsync(cancelationTokenSource.Token); NotifyComplete(); }