I’m trying to create a simple threading procedure (granted this is my first attempt at threading) and all I want to it to do is for each string in an string[] simply go through a void and perform simple folder crawling. However, I’m recieving Method Name expected and i’m unsure of why
string[] FileListing = {@"C:\","E:\"};
foreach (string fl in FileListing)
{
ProjectDirectoryProcessing pjp = new ProjectDirectoryProcessing();
//error here
Thread oThread = new Thread(new ThreadStart(pjp.ProjectProcessor(fl)));
oThread.Start();
}
public class ProjectDirectoryProcessing
{
public void ProjectProcessor(string rootDirectory)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
HashSet<string> DirectoryHolding = new HashSet<string>();
//do some work
//foreach loop
};
}
You need to pass in a delegate, you can do that with a lambda:
But then you would be capturing a loop variable , so make it
Additional
It is quite expensive to make a Thread each time, you’re probably better of using:
Note that
pjpis now created on the thread.