我不知何故觉得我错过了一些基本的东西.这是我的问题.
我正在尝试创建一个System.Threading.Tasks.Task实例来执行接受某种类型参数的操作.我以为我可以做点什么
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.
Run Code Online (Sandbox Code Playgroud)
显然这不会编译.看来我只能使用一个Action<object>而不是Action<T>一个任务,然后在我的方法中将'对象'转换为T.
如何才能最有效,最有效地实现我的目标?