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.