Take the 2-minute tour ×

I had a question here before regarding number of threads in my application but I failed to clarify some of my questions. So I'm here to ask for your expert explanation/answers to my humble inquiry.

Just a background for my question, I'm investigating if there are issues/problems regarding threading in our web application/windows service. So what I did is to create a additional log file to log current running thread counts, current waiting thread counts, and total number of thread in the CurrentProcess. Based on the logs, there are around 40 total threads when the application is idle.


My previous question was "Is this number of threads normal?" I know this is a vague question that is why I got these answers.

Your CurrentProcess is IIS. And yes it is normal for IIS to have a handful of threads at a minimum.

Your ASP.NET site is running in an Application Pool which will have a certain number of threads and may spawn more if needed. Each request is handled in a separate thread so IIS will keep some threads waiting for a request, because it is faster to use existing thread than to start a new one when needed. IIS will also have spare threads in Thread Pool for your application to use. So yes, it is normal for IIS to have multiple threads.

So what I did is to add logs specially at the start of my windows service to know the number of threads at the start of the service and the codes after that.

  1. At the start of the Main() : 15 Threads - What are these threads? According to my logs 14 of these threads have a "Wait" thread state. What are these threads for? Please can someone explain this..
  2. After initializing a list of ServiceHost - 16 Threads (increased by 1)


this.myServiceHosts = new[]
    new ServiceHost(typeof(MyCachingService)),
    new ServiceHost(this._myAService),
    new ServiceHost(new myBService(new BManager()))

//Why is it increased by 1 with this code? Or this code does not have anything to do in the thread count increase?

3. In the OnStart() method of my windows service, I'm opening all the service hosts in my list. I'm executing the code below inside a loop:


I noticed that after executing the code above once (note: there are 7 ServiceHost in my list), the thread count increased by 6 and did not increased anymore after executing the next 6 ServiceHost.Open().

Note: My test machine has 4 cores. I'm sorry if my questions doesn't make sense to someone. I just want to understand more of these.

share|improve this question
The threads are there to do stuff when stuff needs to be done. It's IIS - if you want to know about IIS internals, you will probably have to join the M$ server development team and sign an NDA. –  Martin James Feb 13 '13 at 8:32
Hi @MartinJames, thanks for your reply. So IIS create threads during start of the application to wait for tasks since it will be much slower to create only the thread when it is needed. Do you know any links in msdn about this? Do you have any idea in my 2nd & 3rd questions? –  hisoka21 Feb 13 '13 at 9:05
add comment


Your Answer



Browse other questions tagged or ask your own question.