0
I wanted to know if there is the possibility of creating a list of Actions already passing its parameters to execution, because the number that I will pass to the execution of the same can be variable, so I would like to save these aActions already with its parameters for later only run-all at once.
Follow an example:
public class Program
{
private static List<Task> ListActions = new List<Task>();
static void Main(string[] args)
{
ExecuteMethod();
ExecuteListDeActions();
}
private static void ExecuteMethod()
{
int loop = 10;
while (loop > 0)
{
int valor1 = new Random().Next();
int valor2 = new Random().Next();
int valor3 = new Random().Next();
ListActions.Add(new Task(() => MinhaAction(valor1, valor2, valor3)));
loop--;
}
}
private async static Task<int> MinhaAction(int valor1, int valor2, int valor3)
{
Console.WriteLine("-------------------");
Console.WriteLine("Numero 1: " + valor1);
Console.WriteLine("Numero 2: " + valor2);
Console.WriteLine("Numero 3: " + valor3);
Console.WriteLine("-------------------");
return valor1 + valor2 + valor3;
}
private async static void ExecuteListDeActions()
{
foreach(var a in ListActions)
{
a.Start();
}
Console.ReadLine();
}
}
It is not duplicated my friend, my question is simple and objective, I would like to create a list of Actions already passing the parameters to them and then just run them understand? And do not pass the values of the parameters once you loop in the list. Understand ?
– Nicola Bogar