I had thread arrays in my code which I am going to replace with task.
Dictionary<string, name> threadnames = new Dictionary<string, name>();
public Thread [] Threads;
string[] nodeKeys;
for (int i = 0; i < nodeKeys.Length; i++)
{
Threads[i] = new Thread(() => ThreadMethod(nodeKey));
Threads[i].Name = nodeKey[i];
names.Add(Threads[i].Name, null);
Threads[i].Start();
}
This was the old approach in which I was also saving my thread names in a separate dictionary. Now I am going to convert it to task what so far I have done is this
Dictionary<string, name> threadnames = new Dictionary<string, name>();
string[] nodeKeys;
for (int i = 0; i < nodeKeys.Length; i++)
{
var runningTask = new Task(() => ThreadMethod(nodeKey[i]));
runningTask.Start();
}
Now since all is in for loop, should all of this be done in single task? Or if the above is right approach what about the task id I have to get?
Or if there is better approach to do it will be appreciated.
List<Task>? Why do you need a name or an id?