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

 ̄綄美尐妖づ 提交于 2019-12-19 10:49:19

问题


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

I am using Amazon's SDB c# library which does not use async WebRequests.

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.

Is this the wrong way to achieve this goal? Should I be using async delegates and doing BeginInvoke and EndInvoke?


回答1:


If you just need to queue up some jobs (that don't return values directly) go with ThreadPool.QueueUserWorkItem. It's faster. The difference is covered in other questions (and some great blog entries out there.)




回答2:


Going trully async would require to abandon the Amazon library and roll your own, using BeginGetRequestStream/BeginGetResponse (which I would recommend). If you stick with the sync WebRequests, then use QueueUserWorkItem.



来源:https://stackoverflow.com/questions/1273587/c-asynchronous-delegates-vs-threadpool-queueuserworkitem-when-initiating-many

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!