private void StartButton_Click(object sender, RoutedEventArgs e) { if (_timer.IsEnabled) { _watcher.Stop(); _timer.Stop(); StartButton.Content = "Start"; TimeSpan runTime = TimeSpan.FromMilliseconds(System.Environment.TickCount - _startTime); try { if (runTime.TotalSeconds > 0) { Stats stat = new Stats() { Km = _kilometres, Time = runTime.ToString(@"hh\:mm\:ss"), Date = DateTime.Now }; this.Write(stat); } } catch (Exception) { } } else { _watcher.Start(); _timer.Start(); _startTime = System.Environment.TickCount; StartButton.Content = "Stop"; } }
private void Write(Stats stats) { ObservableCollection<Stats> data = this.Read(); data.Add(stats); IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings; settings.Remove("stats"); settings.Add("stats", data.ToList()); settings.Save(); }