Please tell me, is the asynchronous model correctly implemented in this method?
I need to implement a method that expects the condition to be met, with the possibility of a timeout.
FYI: there is no need to make a generic method
var timeout = timeout == default ? TimeSpan.FromSeconds(30) : timeout;
var stopwatch = new Stopwatch();
stopwatch.Start();
var delayTimeout = 0;
do
{
delayTimeout += 1000;
var report = await MethodAsync();
if (report.Active == true)
{
return report;
}
await Task.Delay(delayTimeout);
}
while (stopwatch.Elapsed < timeout);
throw new TimeoutException($"Timeout.");
DateTime.UtcNowcomparison.