Trusted timer in a console application
I realize that in .NET there are 3 timer kinds (see Comparing the Timer Classes in the .NET Framework Class Library). I have actually picked a threaded timer as the various other kinds can wander if the major string is active, and also I require this to be trusted.
The means this timer operates in the control of the timer is placed on an additional string so it can constantly tick in addition to the job begin finished on the moms and dad string when it is not active.
The concern with this timer in a console application is that while the timer is ticking along on an additional string the major string is refraining anything to the application shuts.
I attempted including a
while true loop, yet after that the major string is also active when the timer does go off.
You can make use of something like
Console.ReadLine() to obstruct the major string, so various other history strings (like timer strings) will certainly still function. You might additionally make use of an AutoResetEvent to obstruct the implementation, after that (when you require to) you can call Set () method on that particular AutoResetEvent challenge release the major string. Additionally make certain that your reference to Timer object does not head out of extent and also waste accumulated.
Consider making use of a ManualResetEvent to obstruct the major string at the end of its handling, and also call
Reset() on it as soon as the timer's handling has actually ended up. If this is something that requires to run frequently, take into consideration relocating this right into a solution procedure as opposed to a console application.