i like to understand what is the difference between Nested Task and Child Task.
var outerTask = Task.Factory.StartNew( () =>
{
var nestedTask = Task.Factory.StartNew( () =>
{
Console.WriteLine("Inside nestedTask");
});
});
A "child task" looks like this:
var parentTask = Task.Factory.StartNew( () =>
{
var childTask = Task.Factory.StartNew( () =>
{
Console.WriteLine("Inside childTask");
}, TaskCreationOptions.AttachedToParent );
});
here i have attach the code.
it seems that when we start any nested task then outer task may complete before inner task but in case of child task always child task complete before parent task. i am not sure that am i right or not. so it will be helpful if anyone guide me when to go for nested task and when child task with sample scenario. thanks