Does AsyncWaitHandle.WaitOne block the CLR thread? Or does it create an I/O completion port?

霸气de小男生 提交于 2019-12-07 15:11:20

问题


I have that question, does AsyncWaitHandle.WaitOne block the CLR thread? or does it create an I/O completion port?

For example, when I run my application I launch a task 'A' that initializes some data, when new requests arrives, I want them to wait till 'A' has finished, so I can do a IAsyncResult.AsyncWaitHandle.WaitOne, but... does it block the calling thread till 'A' ends or does it create a I/O completion port that will be also notified when 'A' finish.

If not, is there a way to do that?

Regards.


回答1:


Yes, it blocks the thread, but like any other WaitHandle, it blocks in the OS kernel so it doesn't take any cpu time.

If you don't want to block your thread, but do want a "callback", you can use the thread pool:

ThreadPool.RegisterWaitForSingleObject( waitHandle, callback, ...


来源:https://stackoverflow.com/questions/8474899/does-asyncwaithandle-waitone-block-the-clr-thread-or-does-it-create-an-i-o-comp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!