In the following code, I pass the action declared outside of StartNew, it looks fine.
Action ac = () => { Console.WriteLine("Executing Action in Task 7!"); };
var t7 = Task.Factory.StartNew(ac );
Task.WaitAny(t7);
But I want to pass the int parameter to the action (I want to declare the action outside of StartNew).
Action<int> ac2 = (n) =>
{
Console.WriteLine("Executing Action with 1 parameter = {0}", n);
};
var t9 = Task.Factory.StartNew( ac2 , 4);
The following code is also good, but I do not want to use Action in this way. I want to define an action outside and call it inside StartNew () as above. How to use ac2 to get the same result as the code below.
var t8 = Task.Factory.StartNew( (n) =>
{
Console.WriteLine("Executing Action in Task 8!");
Console.WriteLine("Param pass {0}", n);
}, 4 );
Task.WaitAny(t8);
source
share