views:

94

answers:

0

Hi,

I have a windows service that is reading data from a database and then submitting it to a WCF serivce. Once that has finished it is stamping a processed date on the original record.

Trouble I am currently having is to do with threading.

The call to the WCF serivce is relatively long and I want to have a number of concurrent calls to the service to help improve the throughput of the windows service.

Currently I have a submitToService method on a new worker class. Upon reading a new row from the database I am creating a new thread which is calling this method.

This obviously isn't too good as the number of threads quickly shoots up and overburdens the WCF service. I have put a thread.sleep in the submit method and am sure to call

System.Threading.Thread.CurrentThread.Abort();

after the submission has finished. However, I don't seem to see the number of threads go down. How can I just have a fixed number of threads that can be used in the windows service? I did think about using a thread pool but read somewhere that wasn't a good choice for a windows service.

Thanks very much.

PS I have added a loop prior to the worker thread creation

while (Process.GetCurrentProcess().Threads.Count > 10)
                        {
                            //sleep for 50ms
                            System.Threading.Thread.Sleep(50);
                        }

But this count never comes down even though I am calling thread.abort on each worker thread. Any ideas?