public override void Load() { new Task(() => { weather = new CurrentWeather(Settings.WeatherHome); weather.DataUpdated += weather_DataUpdated; weather.LoadCachedData(); weather.UpdateData(); }).Start(); }
private void weather_DataUpdated(object sender, EventArgs e) { CurrentWeather weather = (CurrentWeather)sender; bool metric = Settings.WeatherMetric; string _temp = Math.Round(weather.Temperature).ToString(); string _tempUnit = metric ? "°C" : "°F"; string _skyCondition = WeatherFunctions.ProcessSkyConditionString(weather.SkyCondition); string _icon = WeatherFunctions.ProcessSkyConditionImage(weather.SkyCondition, DateTime.Now.TimeOfDay <weather.Sunrise || DateTime.Now.TimeOfDay> weather.Sunset); string _wind = weather.WindDirection + " " + WeatherFunctions.FormatDouble(weather.WindSpeed, 1) + (metric ? " km/h" : " mph"); string _pressure = WeatherFunctions.FormatDouble(weather.Pressure, 1) + (metric ? " hPa" : " in"); string _sunrise = RandomFunctions.FormatTime(weather.Sunrise); string _sunset = RandomFunctions.FormatTime(weather.Sunset); if (weather.ShowTimeZone) { string tzID = " " + weather.TimeZone.Id.Acronym(); _sunrise += tzID; _sunset += tzID; } Dispatcher.BeginInvoke(() => { temp.Text = _temp; tempUnit.Text = _tempUnit; skyCondition.Text = _skyCondition; //ImageSource iconSource = new BitmapImage(_iconUri); //iconSource.Freeze(); //icon.Source = iconSource; icon.Text = _icon; wind.Text = _wind; humidity.Text = weather.Humidity + " %"; cloudCover.Text = weather.CloudCover + " %"; pressure.Text = _pressure; sunrise.Text = _sunrise; sunset.Text = _sunset; grid.Opacity = weather.Timestamp < DateTime.Now.AddHours(-6) ? 0.5 : 1; if (updateTimer != null) { updateTimer.Start(); } }); }