0

I am making a service which is used to monitor status of multiple services running on a server. Every service needs to be monitor in different time intervals. So, For that I am using multiple timers. Something like -

internal System.Timers.Timer Service1CheckTimer;
internal System.Timers.Timer Service2CheckTimer;
.
.
internal System.Timers.Timer ServiceNCheckTimer;

Now, the number of services has reached around 15 and may get increased in future.

So I was wondering, Is it okay to use so many timers? Won't it cause any trouble in the execution if their respective Timer_Elapsed events overlaps each other?

Arpit Gupta
  • 1,209
  • 1
  • 22
  • 39
  • If the intervals are of minutes or longer perhaps consider a check.exe running as a scheduled task configured for each service, that seems simpler and significantly easier to manage & configure. – Alex K. Dec 19 '18 at 13:05
  • This will help you :https://stackoverflow.com/a/44367202/4356387 – A. Gopal Reddy Dec 19 '18 at 13:12
  • Why have *multiple* timers? You shouldn't have to recompile or add yet another timer each time you want to add another service to check. – Panagiotis Kanavos Dec 19 '18 at 13:27
  • This seems the best answer to this question - https://stackoverflow.com/questions/3103150/how-many-system-timers-timer-instances-can-i-create-how-far-can-i-scale?noredirect=1&lq=1 – Arpit Gupta Dec 19 '18 at 14:31
  • 1
    to have multiple timers running at the same time (at their own intervals) should not make any problem (other than race condition if common resource is not synchronised properly). But here any advice is directly dependant on your 'N' .. how many serveries you have to monitor? will you do this approach if there are 1000 services to be monitored. Instead of pulling the status, I would prefer (if possible) service can push you back with the status at certain time interval (there will be pulling but light weighted). Or, i would categorised these services and get the status category wise. – Amit Dec 20 '18 at 12:31
  • 1
    in addition, There are many ways for inter-process communications. you can learn that as well for accepting better approach. – Amit Dec 20 '18 at 12:35

1 Answers1

1

It is generally ok to have multiple timers, even 20 are not an issue. The timers all fire their events on the thread pool. What you might be interested in how many events may happen at the same time - that may cause exhaustion of the available threads in the thread pool and cause delays.

Nick
  • 4,787
  • 2
  • 18
  • 24