Start a task with Action with multiple template args

c#, multithreading, task, templates

Solution

Just use a lambda to convert to the right delegate type:

Action<int, int, int> action = (int p1, int p2, int p3) =>
{
    // do some stuff with p1, p2 and p3.
};

//a closure can capture over any values you might want to pass in
Task.Run(() => action(1, 2, 3));

If your think about it, you cannot hand a `Action<int, int, int>` to `Task.Run` because you also have to supply parameters. `Task.Run` cannot know what you want to pass in.

Problem

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?

Original source