I accidentally bumped into an issue, that I was able to resolve. However, I am a worried about my inability to understand why the error-ed code was able to compile (at first place).
Following is the error-ed code, that compiles fine:
Task<string> myTask = Task<string>.Factory.StartNew(() =>
{
System.Threading.Thread.Sleep(1000);
return "mystrineg";
});
myTask.ContinueWith(t => action, CancellationToken.None,
TaskContinuationOptions.NotOnFaulted, TaskScheduler.Default);
The issue with the above code is : action
won't get called at all.
Here is the fix I made:
Task<string> myTask = Task<string>.Factory.StartNew(() =>
{
System.Threading.Thread.Sleep(1000);
return "mystrineg";
});
myTask.ContinueWith(t => action(t.Result), CancellationToken.None,
TaskContinuationOptions.NotOnFaulted, TaskScheduler.Default);
My question is, why is the compiler allowing to call a parametrized action without an argument?