I wanted to know if there is a possibility to create a list of Actions already passing their parameters to execute, because the numbers that I will pass to the execution of them can be variable, so I would like to save these aActions already with their parameters for later only run them all at once.
Here's 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();
}
}