Groups | Blog | Home
all groups > dotnet performance > february 2006 >

dotnet performance : Thread count increases


John Ballesteros
2/4/2006 4:58:27 PM
Hello,

I've written a Windows service in C#. This service listens a tcp port and
it creates a new thread with every new socket that arrives. This service
also connects to a SQL Server database through a SQLConnection object.

The question is, how do I know if the number of threads of my service is
right? It's happening things that I don't really understand and I want to
know why?

1. In the first line of the main function the thread count is 3. Why?
2. When the service uses the first time the SQLConnection to populate a
datatable with some usefull information the thread count increases to 7!!!! I
just wanted to execute a Select command syncronously, again why it is
increased so much?
3. With the service running and without any connection arriving, suddenly
the thread count rises to 8, why? my code is in a WaitHandle.WaitAny waiting
for some manualresetevent to be raised in the callback of the beginaccept
function.
4. When I start a new thread to work with a new socket the thread count is
increased with 3 new threads, I just started one ( I know that every time I
start a BeginReceive function it starts another thread to monitor the
situation so the framework can execute my callback, but again why 3,
shouldn't it be 2?

Thanks for your help and patience.

Alvin Bruney - ASP.NET MVP
2/27/2006 9:28:52 AM
You ought to use a thread pool for this, creating threads on a per request
basis will cause you to run out of threads rather quickly.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------



"John Ballesteros" <JohnBallesteros@discussions.microsoft.com> wrote in
message news:86694105-7EC9-4DF1-8AA2-5F8DB8472CCB@microsoft.com...
[quoted text, click to view]

AddThis Social Bookmark Button