I somehow feel I am missing something basic. Here's my problem.
I am trying to create a System.Threading.Tasks.Task instance to execute an action that accepts a parameter of a certain type. I thought I could do something like
void DoWork(MyClass obj) {} //My action that accepts a parameter of type 'MyClass'
MyClass obj = new MyClass();
Action<MyClass> action = DoWork; //action that points to the method
Task task = new Task(action,obj); //task that would execute 'DoWork' with 'obj' as the parameter when I call Start.
Obviously this does not compile. It seems I can only use an Action<object>
and not an Action<T>
for a task and then cast the 'object' to T inside my method.
How can I achieve what I want most effectively and efficiently?