Question

I have a C# application that uses a System.Timers timer that repeatedly calls a function. The problem is, depending on the workload, if the processing from a function call reaches a certain CPU usage percentage (98-100%), any subsequent events are blocked.

Is there a way to prevent such a scenario so that events are not blocked?

For example, the timer's event handler is a function that executes dynamic code, which may take some time and resources to process. During such processing a boolean is set to true which causes any subsequent event calls to write to a log file. Once an event's processing has reached a high CPU usage though, additional events will not write to the log file.

Was it helpful?

Solution

Yes, set the Timers property AutoReset to true.

Read: https://msdn.microsoft.com/en-us/library/system.timers.timer(v=vs.110).aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top