65.9K
CodeProject is changing. Read more.
Home

Alternate to Thread.Sleep

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.50/5 (4 votes)

Apr 27, 2011

CPOL
viewsIcon

34134

Thread.Sleep is actually used to block the thread Temporarily for an interval. Async CTP brings forth one probable alternative if you dont want to write yourself : TaskEx.Delay(milliseconds)Probably in next release it will be Task.Delay(milliseconds)This works little different as it...

Thread.Sleep is actually used to block the thread Temporarily for an interval. Async CTP brings forth one probable alternative if you dont want to write yourself :
TaskEx.Delay(milliseconds)
Probably in next release it will be Task.Delay(milliseconds) This works little different as it can work with await, but you can easily put a Task.Wait to get similar result as Thread.Sleep.
Task t = TaskEx.Delay(500);
t.Wait()
is same as
Thread.Sleep(500)
Check my whole article C# 5.0 vNext - New Asynchronous Pattern[^]