I was reading this post Limit the number of parallel threads in C# and trying to use it to send multiple files via ftp at the same time:
Perhaps something along the lines of:
ParallelOptions options = new ParallelOptions();
options.MaxDegreeOfParallelism = 4;
Then in your loop something like:
Parallel.Invoke(options,
() => new WebClient().Upload("http://www.linqpad.net", "lp.html"),
() => new WebClient().Upload("http://www.jaoo.dk", "jaoo.html"));
I am trying to add the files in my directory to the Invoke but I wasn't sure how to add them:
var dirlisting = Directory.GetFiles(zipdir, "*.*", SearchOption.TopDirectoryOnly);
if (!dirlisting.Any())
{
Console.WriteLine("Error! No zipped files found!!");
return;
}
foreach (var s in dirlisting)
{
var thread = new Thread(() => FtpFile.SendFile(s));
thread.Start();
}
I wasn't sure how to add them to the list of files to send. I only want 3 to go up at a time.
How do I add a thread for each file in the directory listing to be sent?