Class Program
{
The static void Main (string [] args)
{
ListListProduct=new List () {
New Product {ID=1, Name="A"},
New Product {ID=2, Name="B"},
New Product {ID=3, Name="C"}};
The Action [] actions=new Action [listProduct. Count];
for (int i=0; I & lt; ListProduct. Count; I++)
{
Var b=I;
The actions [b]=delegate {TaskTest (listProduct [I]); };
}
//write no thread of execution of methods
The foreach (var item in actions)
{
ThreadPool. QueueUserWorkItem (s=& gt; The item (), null);
}
}
The static void TaskTest (Product index)
{
Console. WriteLine ($" current {index. ID} ");
Console.ReadKey();
}
}
Public class Product
{
Public int ID {get; set; }
Public string Name {get; set; }
}
Write no output
CodePudding user response:
The Action into WaitCallbackCodePudding user response:
Because I need need to use the Parallel Invoke, Parallel operation is not supported WaitCallback only support the ActionCodePudding user response:
Since you used the Parallel Invoke, Parallel programming,A: why do we consider the problem of thread pool?
Directly plug multiple action is ok,