I have this code doing what I want:
TriggerSomeExternalProcess();
double secondsElapsed = 0;
DateTime startTime = DateTime.UtcNow;
double timeoutInSeconds = 10;
while (secondsElapsed < timeoutInSeconds) {
// TODO: this seems bad...
secondsElapsed = DateTime.UtcNow.Subtract(startTime).TotalSeconds;
}
CheckStatusOfExternalProcess();
The goal is to TriggerSomeExternalProcess
and then CheckStatusOfSomeExternalProcess
- but that process runs on the same thread so I can't do Thread.Sleep()
. It's an ongoing process that can't be awaited.
I feel like the above while
loop is wrong - what pattern do you employ when you need to wait without blocking your thread?
copy-pasted from a comment on one of the answers unfortunately I can't touch the code in the ExternalProcess. I'm writing a test and those are the methods I have access to. I know it's less than ideal