简体   繁体   中英

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? 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.

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, ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM