What is the standard practice for starting a task with multiple parameters What is the standard practice for starting a task with multiple parameters multithreading multithreading

What is the standard practice for starting a task with multiple parameters


You can do this with a lambda or inline delegate:

myTask = new Task<bool>(() => MyMethod(xyz, abc), _cancelToken);


Using a wrapper class to handle is the standard way to do this. The only thing you can do otherwise is use a Tuple to avoid writing MyParamClass.

mytask = new Task(myMethod, Tuple.Create(xyz, abc), _cancelToken);mytask.Start();bool myMethod(object passedTuple){     var myParamObj = passTuple as Tuple<int, string>;}