コード例 #1
0
        private void SerialPort_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs args)
        {
            try
            {
                var res = _chronograph.Interpret(_serialPortManager.SerialPort);
                res.Order += _worksheetManager.Offset;
                var raceTimeViewModel = new RaceTimeViewModel(res)
                {
                    Resend = new GalaSoft.MvvmLight.Command.RelayCommand <RaceTimeViewModel>(x => SendRaceTime(x))
                };
                System.Windows.Application.Current.Dispatcher.Invoke(() =>
                {
                    if (res.Departure != null)
                    {
                        Departures.Add(raceTimeViewModel);
                        _writer.WriteLine($"1-{res.Order}-{res.Departure}");
                    }
                    else if (res.Arrival != null)
                    {
                        Arrivals.Add(raceTimeViewModel);
                        _writer.WriteLine($"2-{res.Order}-{res.Arrival}");
                    }
                });

                SendRaceTime(raceTimeViewModel);
            }
            catch (Exception ex)
            {
                // I said no crash !
                System.Windows.Application.Current.Dispatcher.Invoke(() =>
                {
                    Logs.Add(ex.Message);
                });
            }
        }
コード例 #2
0
 private void SendRaceTime(RaceTimeViewModel raceTime)
 {
     try
     {
         raceTime.Saved = _worksheetManager.AddRaceTime(raceTime.RaceTime);
     }
     catch (Exception ex)
     {
         System.Windows.Application.Current.Dispatcher.Invoke(() =>
         {
             Logs.Add(ex.Message);
         });
     }
 }