Asynch programming

G

Guest

A couple of questions...

Does the BeginInvoke call spawn a new managed thread, or does it use the
thread pool?

If I pass a delegate for a callback (which _is_ executed on the ThreadPool),
what happens if the thread pool overflows... say I get 30... 40.. or more
callbacks at once?

I'm writing a very threaded application to talk to about 80 hosts... over
TCP. Any advice in general?? I'd like as many simultaneous threads as
possible to get as much data as quickly as possible, but I'm unsure about how
many threads is too much... I don't want the context switching to become
unbearable overhead.

Thanks in advance...
Andrew
 
G

Guest

I've just found the HttpWebRequest.BeginGetResponse() method.

I'm going to write some test code, but if you've had experience with it, I'd
appreciate the feedback, too.

-AJP
 
R

Richard Blewett [DevelopMentor]

Delegate.BeginInvoke queues the method invocation to the ThreadPool.

All requests to teh threadpool are put on a queue. The pool manager controls how many threads service that queue based on things like load, and CPU utilization. The threadpool has an upper limit of 25 threads per piocessor. It isn't documented anywhere (AFAIK) whether the threadpool thread that executed the actual method is the same as the one that makes the callback. If it isn't I would imagine the callback simply gets reposted on the thread pool queue. I must admit I have only ever seen the callback made on the same thread as the method call but i haven't seen that as *documented* behavior.

So no matter what the workload on the threadpool, all that will happen is that the queue fill get fuller.

However:

If you are making network calls you really want to use an async socket request which only ties up the thread while sending the bytes to the network and then when the response comes back as underneath they use IOCompletion ports.

Regards

Richard Blewett - DevelopMentor

http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.framework/<[email protected]>

A couple of questions...

Does the BeginInvoke call spawn a new managed thread, or does it use the
thread pool?

If I pass a delegate for a callback (which _is_ executed on the ThreadPool),
what happens if the thread pool overflows... say I get 30... 40.. or more
callbacks at once?

I'm writing a very threaded application to talk to about 80 hosts... over
TCP. Any advice in general?? I'd like as many simultaneous threads as
possible to get as much data as quickly as possible, but I'm unsure about how
many threads is too much... I don't want the context switching to become
unbearable overhead.

Thanks in advance...
Andrew

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.766 / Virus Database: 513 - Release Date: 17/09/2004



[microsoft.public.dotnet.framework]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top