是否AsyncWaitHandle.WaitOne阻止CLR线程?或者它创建一个I / O完成端口? [英] Does AsyncWaitHandle.WaitOne block the CLR thread? Or does it create an I/O completion port?

查看:394
本文介绍了是否AsyncWaitHandle.WaitOne阻止CLR线程?或者它创建一个I / O完成端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个问题,确实 AsyncWaitHandle.WaitOne 阻止CLR线程?或者它创建一个I / O完成端口?

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

例如,当我跑我的应用程序启动任务'A',它初始化一些数据,当新的请求到来时,我希望他们能等到'A'已经完成,所以我可以做一个 IAsyncResult.AsyncWaitHandle.WaitOne ,但是......它阻塞调用线程,直到'A'端还是它创建将通知还当'A'完成一个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.

如果没有,有没有办法做到这一点?

If not, is there a way to do that?

问候。

推荐答案

是的,它会阻止线程,而是喜欢在OS内核中的任何其他的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:

ThreadPool.RegisterWaitForSingleObject( waitHandle, callback, ...

这篇关于是否AsyncWaitHandle.WaitOne阻止CLR线程?或者它创建一个I / O完成端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆