I need to start a Task in C# so I’m creating an action object.
private Action<int, int, int> action = (int p1, int p2, int p3) =>
{
// do some stuff with p1, p2 and p3.
};
However, when I try and create a task from it I realise that new Task can only take an Action or Action<object> and refuses to accept my action with it’s multiple templated arguments.
Do you have any ideas how I can create this task object and have me pass in the args?
Just use a lambda to convert to the right delegate type:
If your think about it, you cannot hand a
Action<int, int, int>toTask.Runbecause you also have to supply parameters.Task.Runcannot know what you want to pass in.