void Timer_Tick(object sender, DoWorkEventArgs e) { while ((int)Currenttime.TotalSeconds > 0) { if (timer.CancellationPending) // 用户取消操作 { e.Cancel = true; timer.CancelAsync(); return; } if (Currenttime.TotalSeconds <= 3) { TextBackgroundColor = Brushes.Red; } else if (Currenttime.TotalSeconds <= 10) { TextBackgroundColor = Brushes.OrangeRed; } Console.WriteLine("Start!" + Currenttime.ToString()); Currenttime = Currenttime.Add(TimeSpan.FromSeconds(-1)); manualReset.WaitOne(); Thread.Sleep(1000); } }
private void Ticker_Tick(object sender, EventArgs e) { nbrtick += 1; Currenttime = Currenttime.AddMinutes(Vitesse); time.Content = Currenttime.ToShortTimeString(); List <VolProgramme> tmp = new List <VolProgramme>(); foreach (VolProgramme v in Volprogaffiche) { v.setState(Currenttime); if (v.Status == STATE.FLYING) { tmp.Add(v); } } //On supprime les vols partis //l'utilisation d'une liste tampon est //obligatoire : on ne peut pas //modifier une liste pendant qu'on la parcourt. foreach (VolProgramme v in tmp) { Volprogaffiche.Remove(v); } Volprogaffiche.Sort(); mainGrid.DataContext = null; mainGrid.DataContext = Volprogaffiche; if ((nbrtick * Vitesse) / 60 >= Duree) { Console.WriteLine("FIN SIMULATION"); Ticker.Stop(); } }