i just startet thread programming in c#. And I realy dont know if this is the right community to ask questions like that. If not, im sorry.
I have two functions, start() and status(). In start() I create an new task like:
start() {
for each(dir => ListOfAllDirs) {
new Task(() => { yr.LoadAllFiles(dir); }).Start();
}
}
so I have about 200 parallel Tasks Running with this code:
class yr
{
List<Values> rv = new List<Values>();
public List<Values> LoadAllFiles(string dir)
{
[...DoStuff...]
rv.Add(...);
rv.Add(...);
rv.Add(...);
}
}
So I dont know how to access the > 200 running Threads to get the data, before they're finished. I'm looking for sth. like:
status(dir) {
int count = GetTaskByName[dir].rv.Count; (????)
Console.WriteLine("Dir " + dir + "->" + count + "files checked");
}
And the final Output:
Dir AA -> 19 files checkes
Dir AB -> 12 files checkes
Dir BB -> 49 files checkes
Dir AA -> 29 files checkes
So to be clear: 200 dirs, 200 tasks, everything is running asyncron. How do I access a specific Task / get Data from the running Task.
Apparently, you need to take 200 directories and compute a result for each of them. PLINQ makes that exceptionally easy:
And there's your list of directories plus the computation result.
You can do it manually with tasks as well. In that case you probably want a sequence like this: