Many areas of the project I'm working on have a simple timeout check, which basically runs the code through a try loop until 10 seconds succeed or fail.
class Timeout {
private readonly DateTime timeoutDate;
public bool FlagSuccess;
public Timeout() {
timeoutDate = DateTime.UtcNow.AddSeconds(10);
flagSuccess = false;
}
public bool continueRunning() {
if (!flagSuccess && DateTime.UtcNow < timeoutDate) return true;
else return false;
}
}
Here is an example of the class used:
Timeout t = new Timeout();
while (t.continueRunning()) {
try {
t.flagSuccess = true;
}
catch(Exception e) {
Console.WriteLine(e.Message);
}
}
Before implementing this, is there a better and more standard way to do this? What I have above is based on my blind intuition.
source
share