@@ -323,9 +323,7 @@ private void OnAutomatStep(Object source, ElapsedEventArgs e)
323
323
_model . YellowLightState = LightStateEnum . Off ;
324
324
_model . RedLightState = LightStateEnum . Off ;
325
325
326
- _automatTimer . Stop ( ) ;
327
- _automatTimer . Interval = TrafficLightsModel . BlinkingGreenDuration ;
328
- _automatTimer . Start ( ) ;
326
+ SetTimerInterval ( TrafficLightsModel . BlinkingGreenDuration ) ;
329
327
break ;
330
328
331
329
// Мигает зелёным
@@ -337,9 +335,7 @@ private void OnAutomatStep(Object source, ElapsedEventArgs e)
337
335
_model . YellowLightState = LightStateEnum . On ;
338
336
_model . RedLightState = LightStateEnum . Off ;
339
337
340
- _automatTimer . Stop ( ) ;
341
- _automatTimer . Interval = TrafficLightsModel . YellowDuration ;
342
- _automatTimer . Start ( ) ;
338
+ SetTimerInterval ( TrafficLightsModel . YellowDuration ) ;
343
339
break ;
344
340
345
341
// Горит жёлтый
@@ -351,9 +347,7 @@ private void OnAutomatStep(Object source, ElapsedEventArgs e)
351
347
_model . YellowLightState = LightStateEnum . Off ;
352
348
_model . RedLightState = LightStateEnum . On ;
353
349
354
- _automatTimer . Stop ( ) ;
355
- _automatTimer . Interval = TrafficLightsModel . RedDuration ;
356
- _automatTimer . Start ( ) ;
350
+ SetTimerInterval ( TrafficLightsModel . RedDuration ) ;
357
351
break ;
358
352
359
353
// Горит красный
@@ -365,9 +359,7 @@ private void OnAutomatStep(Object source, ElapsedEventArgs e)
365
359
_model . YellowLightState = LightStateEnum . On ;
366
360
_model . RedLightState = LightStateEnum . On ;
367
361
368
- _automatTimer . Stop ( ) ;
369
- _automatTimer . Interval = TrafficLightsModel . RedAndYellowDuration ;
370
- _automatTimer . Start ( ) ;
362
+ SetTimerInterval ( TrafficLightsModel . RedAndYellowDuration ) ;
371
363
break ;
372
364
373
365
// Горит красный и жёлтый
@@ -379,9 +371,7 @@ private void OnAutomatStep(Object source, ElapsedEventArgs e)
379
371
_model . YellowLightState = LightStateEnum . Off ;
380
372
_model . RedLightState = LightStateEnum . Off ;
381
373
382
- _automatTimer . Stop ( ) ;
383
- _automatTimer . Interval = TrafficLightsModel . GreenDuration ;
384
- _automatTimer . Start ( ) ;
374
+ SetTimerInterval ( TrafficLightsModel . GreenDuration ) ;
385
375
break ;
386
376
387
377
default :
@@ -391,6 +381,17 @@ private void OnAutomatStep(Object source, ElapsedEventArgs e)
391
381
ProcessState ( ) ;
392
382
}
393
383
384
+ /// <summary>
385
+ /// Настраиваем интервал таймера
386
+ /// </summary>
387
+ private void SetTimerInterval ( int interval )
388
+ {
389
+ _automatTimer . Stop ( ) ;
390
+ _automatTimer . Interval = interval ;
391
+ _automatTimer . Start ( ) ;
392
+ }
393
+
394
+
394
395
395
396
#endregion
396
397
}
0 commit comments