Jacko
Jacko

Reputation: 13195

c#: is there any reason to favour asynchronous socket call to synchronous calls in my own thread pool?

Is there any performance advantage in calling BeginGetResponse vs. calling GetResponse in my own thread pool? The advantage of my own pool is that I can control the queue of requests.

Thanks!

Upvotes: 3

Views: 307

Answers (1)

BFree
BFree

Reputation: 103740

When you call GetResponse, even if you call it on a background ThreadPool thread, THAT thread will still be blocked, and won't be able to go and do other work. That means context switching etc. If however you use the BeginGetResponse, then it offloads the work to the network card, however and most importantly, the calling thread is now free to go about and do some other work. When the network card is done, it'll notify your application, at which point the callback will get called.

Upvotes: 1

Related Questions