I am trying to create a system in which the trigger fires, so the doors open for 5 seconds and then close again. I am using Threading.Timer to do this using:
OpenDoor(); System.Threading.TimerCallback cb = new System.Threading.TimerCallback(OnTimedEvent); _timer = new System.Threading.Timer(cb, null, 5000, 5000); ... void OnTimedEvent(object obj) { _timer.Dispose(); log.DebugFormat("All doors are closed because of timer"); CloseDoors(); }
When I open a certain door, the timer starts. After 5 seconds, everything closes again.
But when I open some door, wait 2 seconds, then open another door, everything closes after 3 seconds. How can I reset the timer?
source share