private void UpdateDisplay() { try { using (new WaitCursor()) { if (this.provider == null) { this.provider = Provider.Create(); } this.weather = this.provider.GetWeatherAsync(this.settings).Result; // Changing the root DataContext will cause all of the bindings to update. this.DataContext = this.weather; this.UpdateTimer(this.weather.IsValid); } } catch (Exception ex) { var properties = this.GetLogProperties(); properties.Add("Location", this.settings.UserLocation); Log.Error(typeof(Stats), "An error occurred updating the display.", ex, properties); this.UpdateTimer(false); // If an error occurs on every timer interval, make sure we only show one MessageBox at a time. if (!this.showingError) { this.showingError = true; try { StringBuilder sb = new StringBuilder(); Exceptions.ForEach(ex, (exception, depth, parent) => sb.Append('\t', depth).Append(exception.Message).AppendLine()); if (ApplicationInfo.IsDebugBuild) { // Show the root exception's type and call stack in debug builds. sb.AppendLine().AppendLine(ex.ToString()); } string message = string.Format( "{0}: {1}{2}{2}{3}", this.Info.GizmoName, this.settings.UserLocation, Environment.NewLine, sb.ToString().Trim()); WindowsUtility.ShowError(this, message); } finally { this.showingError = false; } } } }
public Stats() { this.InitializeComponent(); this.settings = Settings.Default; this.weather = new WeatherInfo(this.settings); this.timer = new DispatcherTimer { Interval = Properties.Settings.Default.WeatherRefreshInterval }; this.timer.Tick += (s, e) => this.UpdateDisplay(); }
public async Task UpdateWeatherAsync(WeatherInfo weather) { this.Weather = weather; await this.UpdateAsync().ConfigureAwait(false); }