Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would I use Sleep() with infinite timeout?

According to MSDN, Sleep() can be provided INFINITE value and that "indicates that the suspension should not time out".

Why would I want to call Sleep() with INFINITE timeout in my program?

like image 713
sharptooth Avatar asked Dec 14 '22 01:12

sharptooth


2 Answers

I have used Sleep(INFINITE) and it makes perfect sense. I've used it to keep the thread alive. I have registered for WMI notification event (ExecNotificationQueryAsync, which receives event notification infinitely) then you need to keep the application alive. dont' know if this make sense to you.

like image 187
Pritesh Acharya Avatar answered Dec 22 '22 06:12

Pritesh Acharya


A sleep with no timeout does not need a timer. This reduces the overhead where you anticipate a variable-length wait but are absolutely sure that the thread will be resumed.

like image 21
Steve De Caux Avatar answered Dec 22 '22 04:12

Steve De Caux