I'm working with Tasks in C#. I'm having an issue with function invocation when I add my functions to the List. What happens is, instead of waiting until the Task.WhenAll(...) to invoke all functions at once, it invokes them immediately when added...only whenever I need to add them as a NameOfFunction() (so with parenthesis, with or without params).
This does not work and causes invocation immediately:
List<Task> rtcTasks = new List<Task>();
rtcTasks.Add(RunInitialProcess());
rtcTasks.Add(RunSecondaryProcess());
Task.WhenAll(rtcTasks).Wait();
This does work and invokes all when the process reaches Task.WhenAll(...);
List<Task> rtcTasks = new List<Task>();
rtcTasks.Add(Task.Run(RunInitialProcess));
rtcTasks.Add(Task.Run(RunSecondaryProcess));
Task.WhenAll(rtcTasks).Wait();
My issues is, I'd like to pass in functions that contain arguments that I can use for handling very easily without having to declare accessible objects in the current class I'm in.
Both functions are:
private async Task FunctionNameHere(){...}