[英]Does AsyncWaitHandle.WaitOne block the CLR thread? Or does it create an I/O completion port?
I have that question, does AsyncWaitHandle.WaitOne
block the CLR thread? 我有这个问题,
AsyncWaitHandle.WaitOne
阻止了CLR线程吗? or does it create an I/O completion port? 或者它是否创建了I / O完成端口?
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. 例如,当我运行我的应用程序时,我启动一个初始化某些数据的任务'A',当新请求到达时,我希望它们等到'A'结束,所以我可以做一个
IAsyncResult.AsyncWaitHandle.WaitOne
,但是。 ..它是否阻止调用线程直到'A'结束或创建一个I / O完成端口,当'A'完成时也会通知它。
If not, is there a way to do that? 如果没有,有没有办法做到这一点?
Regards. 问候。
Yes, it blocks the thread, but like any other WaitHandle
, it blocks in the OS kernel so it doesn't take any cpu time. 是的,它会阻塞线程,但是像任何其他
WaitHandle
,它会在操作系统内核中阻塞,因此不需要任何CPU时间。
If you don't want to block your thread, but do want a "callback", you can use the thread pool: 如果您不想阻止线程,但确实需要“回调”,则可以使用线程池:
ThreadPool.RegisterWaitForSingleObject( waitHandle, callback, ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.