private void button_Click(object sender, RoutedEventArgs e) { factory = new FactoryPerson(); queue = new Queue(); GuardedSuspension.TimeForPull = TimeSpan.FromMilliseconds(Convert.ToInt32(Queue.Text)); GuardedSuspension.TimeForPush = TimeSpan.FromMilliseconds(Convert.ToInt32(newClient.Text)); GuardedSuspension.Counter = 0; timer1 = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(50) }; timer = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(50) }; timerRed = new DispatcherTimer() { Interval = GuardedSuspension.TimeForPull }; timerGreen = new DispatcherTimer() { Interval = GuardedSuspension.TimeForPush }; Iteration = new GuardedSuspension(queue, factory); List.Items.Clear(); timer1.Tick += Timer1_Tick; timer.Tick += Timer_Tick; timerRed.Tick += TimerRed_Tick; timerGreen.Tick += TimerGreen_Tick; timer1.Start(); timer.Start(); timerRed.Start(); timerGreen.Start(); }
private void Timer1_Tick(object sender, object e) { if (Iteration.StartNew()) { Iteration = new GuardedSuspension(queue, factory); List.Items.Add(Iteration.Result().ToString()); GuardedSuspension.Counter++; } if (GuardedSuspension.Counter == 29) { (sender as DispatcherTimer).Stop(); } }