public override bool OnStartJob(JobParameters @params) { _reschedule = true; _downloadTask = Task.Run(async() => { Debug.WriteLine("FETCH"); try { bool success = await WeatherDataFetcher.UpdateWeatherForecastDbAsync(); if (!success) { Debug.WriteLine("No new Data was fetched during background task"); _reschedule = true; } Debug.WriteLine("Background fetching SUCCESS"); _reschedule = false; } catch (Exception e) { Debug.WriteLine("Error occured during background fetching: " + e.StackTrace); _reschedule = true; } Debug.WriteLine("Job finished @ " + DateTime.Now); JobFinished(@params, false); if (Build.VERSION.SdkInt >= BuildVersionCodes.N) { Util.ScheduleJob(this); } }); Debug.WriteLine("Service running @ " + DateTime.Now); return(true); }
private async void TimerEventProcessor(object sender, EventArgs e) { _lightControlThread?.Abort(); CurrentWeather currentWeather = await WeatherDataFetcher.GetWeatherAsync(); SetUi(currentWeather); var colorController = new ColorController(currentWeather.Temperature, currentWeather.CurrentConditionId); _lightControlThread = new Thread(new ThreadStart(colorController.SetColors)) { IsBackground = true }; _lightControlThread.Start(); }
public override void PerformFetch(UIApplication app, Action <UIBackgroundFetchResult> completionHandler) { Debug.WriteLine("FETCH"); try { bool success = WeatherDataFetcher.UpdateWeatherForecastDbAsync().Result; if (!success) { completionHandler(UIBackgroundFetchResult.NoData); } completionHandler(UIBackgroundFetchResult.NewData); } catch (Exception e) { Debug.WriteLine("Error occured during Background Fetching: " + e.StackTrace); } }
public MainPage(int id) { _mId = id; InitializeComponent(); Options.IsEnabled = DependencyService.Get <ISettingsService>().SettingsDialogueAvailable; DependencyService.Get <ISettingsService>().PropertyChanged += (sender, e) => { DemoList.BeginRefresh(); DemoList.RefreshCommand.Execute(DemoList); DemoList.EndRefresh(); }; if (WeatherDataFetcher.LastUpDate.Date <= DateTime.Now.AddDays(-2)) //is this how you use async things??? { WeatherDataFetcher.UpdateWeatherForecastDbAsync(); } }