I want to create a task to run a foo function for each item in the list. In the below code, let us say function Foo takes 20 seconds to run. By the time the task completes, the main thread would have exited the scope in which the task t was created. When the task t goes out of scope for the main thread, would the main thread delete the thread t?
void CreateTaskAndRun()
{
...doing something
foreach(DummyClass obj in objList)
{
Task t = new Task(obj.Foo);
t.Start(); //Foo takes 20 seconds to run
}
...doing something
}