I have a scenario where I would like to invoke functions but want them to be invoke conditionally. So in the below code only function 2 and 3 will be invoked. However, the Action part doesnt return a value but in my case I want to store the return value.
List<int> list = new List<int> {2,3};
Dictionary<int, Action> actions = new Dictionary<int, Action>()
{
{1, Function1},
{2, Function2},
{3, Function3}
};
Parallel.Invoke((from action in list select actions[action]).ToArray());
Initially what I had was below code but this would invoke all the functions. Any thoughts?
Parallel.Invoke(
() => return1=function1,
() => return2=function2,
() => return3=function3
);