Does AsyncWaitHandle.WaitOne block the CLR thread?

2019-05-11 09:50发布

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条回答
祖国的老花朵
2楼-- · 2019-05-11 10:43

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, ...
查看更多
登录 后发表回答