开发者

Does AutoResetEvent.WaitOne() frees a slot in the thread pool?

开发者 https://www.devze.com 2022-12-12 17:30 出处:网络
I am trying to synchronize an asynchronous method. The main advantage of the async version is that it frees a slot in the thread pool. I would like to keep this advantage in my开发者_JS百科 sync versi

I am trying to synchronize an asynchronous method. The main advantage of the async version is that it frees a slot in the thread pool. I would like to keep this advantage in my开发者_JS百科 sync version. When I use AutoResetEvent.WaitOne() it is equivalent to a Thread.Sleep() in terms of thread pool usage?


When you call WaitOne the current thread will block and wait for the event to be signaled. Just like with Thread.Sleep the thread will not be released to the thread pool. The difference is that with Thread.Sleep you need to specify a fixed time during which the current thread will be blocked, while WaitOne will block until some other thread calls Set or a timeout occurs.

0

精彩评论

暂无评论...
验证码 换一张
取 消