Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

Networking and Multithreading in .NET

Hi

Posted this in ?joel allready but no answers there, this is probably a better place ;)

I´m currently working on a little app that scans the shared folders of the computers on my school´s LAN and puts the filenames in a database. The LAN has < 400 computers that have the names xyz000 - xyz400. Many of those may be offline at the time of scanning and some numbers aren´t actually used. When I try to connect to a machine that doesn´t exist it takes a pretty long time to figure out if it doesn´t exist (I just use if (Directory.Exists("\\xyz4000\temp") so I started using many threads to do this in parallel so I wouldnt have to wait so long for the disconnected machines.

So finally, here are my questions:

1. How many threads can I have going at one time? Can I have 400 threads running without it being some kind of problem? I also thought about having some kind of threadpool but am not sure how to implement it.

2. Is there some way that I can get a list of the connected computers on the LAN? Don´t know if Active Directory is used or if that has anything to do with this :)

3. Is there a limit to how many computers I can connect to at the same time?

thanks in advance

...
Friday, June 24, 2005

1. How many threads can I have going at one time?
A:  As many as you like, but too many and you'll bog down the machine.  It may take some tuning to find out how many work best for your app.

Can I have 400 threads running without it being some kind of problem?
A:  That sounds a bit extreme.

I also thought about having some kind of threadpool but am not sure how to implement it.
A:  You can use the threadpool class in .NET, but it has a limited size by default.  There is code out there to change the thread pool size.  I can email it to you if you like.  I had an issue with the thread pool when requesting too much work from it, it would throw an error.  I ended up using the thread pool, but creating my own queuing mechanism around it.

2. Is there some way that I can get a list of the connected computers on the LAN?
A:  I'm sure there is, because Window's explorer knows what computers are connected on my Workgroup at home, but I don't know they API call.

Don´t know if Active Directory is used or if that has anything to do with this :)
A:  AD is not the place for this (AFAIK).

3. Is there a limit to how many computers I can connect to at the same time?
A:  I've never head of a limit, but I wouldn't doubt it.

ian
Monday, June 27, 2005

2. You can use NetServerEnum, but the list is not 100% reliable:

http://pinvoke.net/default.aspx/netapi32.netserverenum

3. I believe the connection limit is 10 for XP Pro and 5 for XP Home:

http://support.microsoft.com/?scid=kb;en-us;314882

Jeff Mastry
Monday, June 27, 2005

*  Recent Topics

*  Fog Creek Home