Hi,
I am developing a port scanner application that displays the open/closed ports in any system and outputs them to a richtextbox.
My program works fine, but for the following issue:-
I use a function that scans the ports.
I tried calling this function using a thread pool as well as the thread class.
But using the pool returns an exception at Appllication.run(new form1) and the program stops for ports greater than 50 upto 5/10 port it doesn't crash and the UI update of the list also occurs once all port have been scanned which is unusual since I am displaying them at the end of each function.
I used the Thread class to scan 11000 ports it goes upto 2000 threads and then an error stating out of memory with huge np pool.
I am not sure how to go about actually doing this efficiently using threads.
If I don't use threads, the program woks fine but the time taken is too long to return the results.
Thanks for your help in advance,
Karthik Narasimhan

Suggestion request for winforms app
Carlos Gonzalez
If you want to use threads in a port scanning type of application, then you should determine 1) How many max threads your application will use.
For example, lets say you will use 50 max, then when your client decides to scan port range 1-2000 thread 1 scans 1-40, 2 scans 41-80, 3 scans 81-120, etc.
You do not want to have one thread just do 'see if port is active', thats not good at all.
Jackuline
Threads are powerful, but must be used properly. 2000 thread is not good, you do not have 2000 CPU and context switching will eat a lot of CPU power. Right now my PC have 670 threads, but 2000 more... Surely this is not good.
I think best way is to run 1 or 2 threads, make them repeatedly scan this ports and report results to UI thread each second or two. Can you post here code you use to scan/report so we can find solution