简体   繁体   English

C#:启动许多连接时,异步委托与ThreadPool.QueueUserWorkItem

[英]C#: Asynchronous delegates vs ThreadPool.QueueUserWorkItem when initiating many connections

I have to send many web service calls out to delete a bunch of records in Amazon SDB (unfortunately, rows can only be deleted one at at time currently). 我必须发出许多Web服务调用才能删除Amazon SDB中的一堆记录(不幸的是,当前只能一次删除一行)。

I am using Amazon's SDB c# library which does not use async WebRequests. 我正在使用不使用异步WebRequests的Amazon SDB c#库。

Currently I use ThreadPool.QueueUserWorkItem to queue up a bunch of calls (I configured my connectionManagement maxconnection to allow for a bunch of connections) this works well..as the request is sent out, it blocks and another request is made. 目前,我使用ThreadPool.QueueUserWorkItem将一堆调用排队(我将我的connectionManagement maxconnection配置为允许一堆连接),这很好..随着请求被发送出去,它阻塞了,并发出了另一个请求。

Is this the wrong way to achieve this goal? 这是实现这个目标的错误方法吗? Should I be using async delegates and doing BeginInvoke and EndInvoke? 我应该使用异步委托并执行BeginInvoke和EndInvoke吗?

If you just need to queue up some jobs (that don't return values directly) go with ThreadPool.QueueUserWorkItem . 如果您只需要排队一些作业(不直接返回值),请使用ThreadPool.QueueUserWorkItem It's faster. 它更快。 The difference is covered in other questions (and some great blog entries out there.) 其他问题 (以及一些出色的博客文章)涵盖了差异。

Going trully async would require to abandon the Amazon library and roll your own, using BeginGetRequestStream/BeginGetResponse (which I would recommend). 完全异步将需要使用BeginGetRequestStream / BeginGetResponse(我建议)放弃Amazon库并推出自己的库。 If you stick with the sync WebRequests, then use QueueUserWorkItem. 如果您坚持使用同步WebRequests,请使用QueueUserWorkItem。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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