What's the best way to sleep a certain amount of time, but be able to be interrupted by a IsCancellationRequested
from a CancellationToken
?
I'm looking for a solution which works in .NET 4.0.
I'd like to write
void MyFunc (CancellationToken ct)
{
//...
// simulate some long lasting operation that should be cancelable
Thread.Sleep(TimeSpan.FromMilliseconds(10000), ct);
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…