Task.Factory.StartNew((param,param2) => { Console.WriteLine("Test"); },
TaskCreationOptions.None);
Error 1 Delegate ‘System.Action’ does not take 2 arguments
I am getting the above error. Couldn’t understand what’s going wrong.
Edited: Why it is accepting single parameters then
Task.Factory.StartNew((param1) =>
{
for (int j = 0; j < 10; j++)
{
Console.WriteLine(string.Format("Task : {0}, outputing {1}- {2}",
param1, j.ToString(), param1));
}
}, string.Format("Tast Count " + ic++.ToString()));
There are several overloads to the
Task.Factory.StartNewmethod. The two you’ve mentioned in your question are:The methods do considerably different things. The item of note, though, is the difference between
ActionandAction<object>. Lambdas are essentially anonymous methods, so to get a visual of what these are, let’s convert them to method signatures.In your first example, which doesn’t compile, it is equivalent to the last one. There is no overload for
Task.Factory.StartNewthat takes multiple parameters.