private void btnStart_Click(object sender, RoutedEventArgs e) { if (!fanGenerator.IsAlive) { ResetData(); fanGenerator = new Thread(FanGenerator); fanGenerator.Start(); CurrStadium.StartServicingVisitors(); } }
private void btnStop_Click(object sender, RoutedEventArgs e) { try { fanGenerator.Abort(); CurrStadium.ResetData(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void FanGenerator() { try { bool isStadiumFull = false; while (!isStadiumFull) { ushort countPlaces = 0; ushort countSectors = 0; this.Dispatcher.Invoke(() => { countSectors = CurrStadium.CountSectors; countPlaces = (ushort)(CurrStadium.CountPlaces / CurrStadium.CountSectors); CurrStadium.IsStadiumFull(); isStadiumFull = CurrStadium.IsStadiumFull(); }); Fan fan = GenerateFan(countSectors, countPlaces); int generateFunSleep = 0; this.Dispatcher.Invoke(() => { CurrStadium.EntranceStadiumQueue.Add(fan); generateFunSleep = GenerateFunSleep; }); Thread.Sleep(generateFunSleep); } } catch (ThreadAbortException ex) { MessageBox.Show(ex.Message + " FanGenerator."); } catch (Exception e) { MessageBox.Show(e.Message); } }
private void myUpDownControl_ValueChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { CurrStadium.CountPlacesChanged(); }