From: nok on
I have a Windows service which is activated at regular intervals by a
System.Timers.Timer event.
It checks i any data is available and, if so, sends several hundred SOAP
messages to a webservice.
The data is sent synchronously so most of the time is spent waiting for the
request to return from the remote server.
I would like to have n (configurable) threads to do the sending. When a
request is ready to be sent use one of the n threads if one is available,
otherwise wait for one to be free. I have looked at the different techniques
for threading but I dont know which is appropriate here.
I want to limit the sending to n threads in order not to overload the web
service (and myself since the requests in turn generate requests to my
server) Each thread is to wait for its request to complete just like before.

If i use the ThreadPool i can see how to queue up all the requests. But must
I wait for the last one to complete before the timer event return, or does
the thread that runs the timerevent live beyond the return?

If I use ThreadPool.SetMaxThreads to set "n", does it affect only the
execution of my timerevent?

Thanks
Ove