AsyncWaitHandle.WaitOne 是否会阻塞 CLR 线程?或者它会创建一个 I/O 完成端口吗?
我有这个问题,AsyncWaitHandle.WaitOne
是否会阻塞 CLR 线程?或者它是否创建一个 I/O 完成端口?
例如,当我运行应用程序时,我启动一个任务“A”来初始化一些数据,当新请求到达时,我希望它们等待“A”完成,这样我就可以执行 IAsyncResult.AsyncWaitHandle.WaitOne ,但是...它是否会阻塞调用线程直到“A”结束,或者是否创建一个 I/O 完成端口,当“A”完成时也会收到通知。
如果没有,有办法做到吗?
问候。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,它会阻塞线程,但与任何其他
WaitHandle
一样,它会阻塞操作系统内核,因此不会占用任何 CPU 时间。如果您不想阻塞线程,但确实想要“回调”,则可以使用线程池:
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: