-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
executable file
·39 lines (35 loc) · 1.38 KB
/
Program.cs
File metadata and controls
executable file
·39 lines (35 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using trafficlight.TrafficLightControls;
namespace trafficlight
{
internal class Program
{
public static void Main(string[] args)
{
DateTime? timeOfLastException = null;
while (true)
{
try
{
ITrafficLightControl control = new Disco(new TrafficLightInterface());
control.Activate();
}
catch (Exception e)
{
/*
* Sometimes the connection to the traffic light interface is interrupted, e.g. by power cycling.
* By catching the exception here, we can try to recreate the TrafficLightInterface and continue,
* rather than having to terminate the program. However, if there's another issue which will cause
* exceptions to be continually thrown, then we should give up and terminate.
*/
var currentDateTime = DateTime.UtcNow;
if (timeOfLastException.HasValue && (currentDateTime - timeOfLastException.Value).TotalMinutes < 1)
{
throw e;
}
timeOfLastException = currentDateTime;
}
}
}
}
}