How to "sleep" until timeout or cancellation is requested in .NET 4.0
Alternatively, I think this is pretty clear:
Task.Delay(waitTimeInMs, cancellationToken).Wait(cancellationToken);
I just blogged about it here:
CancellationToken and Thread.Sleep
in Short:
var cancelled = token.WaitHandle.WaitOne(TimeSpan.FromSeconds(5));
In your context:
void MyFunc (CancellationToken ct)
{
//...
// simulate some long lasting operation that should be cancelable
var cancelled = ct.WaitHandle.WaitOne(TimeSpan.FromSeconds(10));
}