Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 977
Mike Chaliy Avatar asked Aug 16 '26 11:08

Mike Chaliy


1 Answers

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.

like image 174
achekh Avatar answered Aug 18 '26 02:08

achekh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!