如何使异步回调在不同的线程池中处理?
当执行 begin... 异步调用时,我传递的委托在默认线程池中处理(根据文档)。
例如:System.IO.Stream.BeginRead( byte[] 缓冲区、int 偏移量、int 计数、 AsyncCallback回调,对象状态);
如何才能使用专用线程池进行异步方法处理?
(我知道这是可以做到的,因为 CCR(并发协调运行时)也在这样做(根据他们的文档))
When doing a begin... async call, the delegate I pass is handled (according to the documentation) in the default threadpool.
for instance: System.IO.Stream.BeginRead(
byte[] buffer, int offset, int count,
AsyncCallback callback, object state);
How can I make it so that I can use a dedicated threadpool for async method handling?
(I know this can be done since the CCR (Concurrency Coordination Runtime) is also doing this (according to their documentation))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
严格来说,它是在线程池的 IO 部分中处理的(异步 IO 操作有自己的线程集,与 ThreadPool.Queue* 方法使用的线程分开)。
目前(使用已发布/支持的工具)执行此操作的唯一方法是将存根方法传递给
BeginRead
,将执行转发到您自己的线程池:响应式框架扩展 (RX) 将使这更容易:为您的线程池创建一个 IScheduler 实现,但 RX 是一个 CTP,并且可能需要一段时间才能以任何形式上线。
Strictly speaking it is handled in the IO part of the thread pool (asynchronous IO operations have their own set of threads separate from those used by
ThreadPool.Queue*
methods).About the only way to do this currently (with released/supported tools) would be to have a stub method passed to
BeginRead
that forwards execution to your own thread pool:The Reactive Framework Extensions (RX) would make this easier: create an
IScheduler
implementation for your threadpool, but RX is a CTP and likely to be a while before any form of go live.