Mike Chaliy
Mike Chaliy

Reputation: 26698

Is Task.Delay non blocking?

Task.Delay uses System.Threading.Timer internally. Main question is System.Threading.Timer non-blocking for my application? If I make:

await Task.Delay(15)

Does code bellow utilize threads for 15ms? Or will it use OS to make callback. Where to find information about this?

Upvotes: 3

Views: 999

Answers (1)

achekh
achekh

Reputation: 1106

According to Jeffrey Richter (page 748):

Internally, the thread pool has just one thread that it uses for all Timer objects. This thread knows when the next Timer object’s time is due. When the next Timer object is due, the thread wakes up, and internally calls ThreadPool’s QueueUserWorkItem to enter an entry into the thread pool’s queue, causing your callback method to get called.

That means that you'll have at least two worker threads when timer is executed: one - internal for timer and another - for the actual worker process.

Upvotes: 4

Related Questions