I'm trying to build code that constantly monitors if one or several machines out of ~20 go into an error-state. During operation they can go into error for a few minutes or seconds, that's not what I'm looking for. I am explicitly looking for errors that prevail for more than 3 minutes. If such an error is detected, a notification e mail should be sent. Sending an e-mail is not the problem, but the monitoring. Does somebody know the answer for this?
I have already tried to solve this problem with a while-loop and a counter, together with thread.sleep(5000), but I have been told, that's not a good solution, as the rest of the code should still constantly run and send updates. The part I show here is just a small piece of thousands of lines that have been created by someone else.
I tried to store the current time in the variable storage to then compare it to the current Time(future time). If they are 3 minutes apart, it should send mail. I know that this isn't very logical, it doesn't even work.
if (secLevelRed == true)
{
DateTime TimeStorage = DateTime.Now;
if (TimeStorage.AddMinutes(3)==DateTime.Now)
{
//Create the Email
//code edited out
}
}