I am using following code for creating parent and child task. Parent task's job is just wait for 5 sec and child task executes and stored result in shared resource. I have marked that child task is taking time.
Actually I don't know internal mechanism that when child thread is created and start execution parallel ?
Is there any documentation from that I can know or Is there any other best way to implement parent child concept ?
List<Task> taskList = new List<Task>();
Task parentTask = Task.Factory.StartNew(() =>
{
int index = 0;
for (int i = 0; i < 10; i++)
{
var task = new Task(() => PrintHello(), TaskCreationOptions.AttachedToParent);
taskList.Add(task);
index++;
}
foreach (Task task in taskList)
{
task.Start();
}
});
//Wait Parent Task.
parentTask.Wait(5000);
EDIT:
Application is too heavy (avg 5 request per sec) and It should give response in 5 sec.
I am using task for better performance. Is there any other way other than task for parallelism ?