I am trying to get grasp of .NET 4.0+ Task Parallel Library concepts...
In the following C# 4.0 code snippet:
Task t = Task.Factory.StartNew(() =>
{
Console.WriteLine("I am the task");
return "res1";
});
why compiler doesn't (and run-time either) produce any error if the return cannot be used unless generic Task used instead:
Task<string> t = Task.Factory.StartNew(() =>
{
Console.WriteLine("I am the task");
return "res1";
});
Or it (returned object) can be used?
Do I understand correctly that <string>
in Task<string>
is needed only for detecting or assuring the type of return (ed object) or of t.Result
?
Or there are any other hidden from me necessities except this?
Why this type cannot cannot be determined from the type of returned object?
I.e. why is the Result property of a task unavailable for non-generic tasks?