.net construct for while loop with timeout
问题 I commonly employ a while loop that continues to try some operation until either the operation succeeds or a timeout has elapsed: bool success = false int elapsed = 0 while( ( !success ) && ( elapsed < 10000 ) ) { Thread.sleep( 1000 ); elapsed += 1000; success = ... some operation ... } I know there a couple of way to implement this, but the basic point is that I repeatedly try some operation with a sleep until success or I've slept too long in aggregate. Is there a built-in .net class/method