It's a big BIG code subject, I think you'll have to be more specific about whats going on, BUT i'll offer my first impressions.
I've done something similar with http gets. Spawning off threads to grab a web pages html from 2000 different locations. Not exactly the same but I can offer some info.
One, I have found that when I get to 1200 or so threads windows will just quit...at least on my PC and image. With the standard xp kernal running 650 or so threads baseline, adding another 800 is iffy. You can get the number of threads running from the task manager FYI.
I will go on the assumption that what you are trying to do is spin the thread, open the connection, copy the file, close connection, terminate thread.
Based on the above assumption, I will assume you are wanting to only have x number of threads open at any one time.
My quite inelegant solution was this. Create a loop to spin off the threads and add a sleep command to control the number of threads. Not elegant, code lawyers would hate it, but it works well. My https gets are high latency and I have found spinning off 10 per second to work well in my case thread.sleep(100)
For Each objSite_ As SiteClass In SiteClassArray_
Dim objSS_ As New GetHttpData(objSite_, timeout_)
Dim t As Thread = New Thread(AddressOf objSS_.Go)
t.IsBackground = True
t.Name = objBranch_.BrDbSiteID & "1"
t.Start()
Thread.Sleep(100)
Next
What size is the file? If it's huge, you may need less or more threads/sec. I would think you could, through trial and error, find a relationship between the size of the file and the number of threads per second your pc can handle ex.
10 meg file = 10 threads/sec
1 meg file = 25 threads/sec
100 meg file = 2 threads/sec
Once you develop your relationship, your program could calculate the thread sleep time based on file size to be transmitted.
I like to make sure my threads quit, so I do use the thread.currentthread.abort to close down each thread. Not sure if you want to do that or not.
I've tried to figure out thread pools, never got anywhere with them, so I've just been using the above method.
Proxy servers caused me much headache. It seems when you test your code with VB's Debug the Debug "host" uses IE's proxy settings while a compiled program does not. Lost a couple of weeks to that one.
So I found some code to create proxy bypasses before doing my http gets...again, not sure if that applies to sockets.
Finally, I would REALLY like to know how to copy a file via sockets. Could you help me with that?
Enter your message below
Sign in or Join us (it's free).