Home > Net >  The issue of multithreading create mass participation..
The issue of multithreading create mass participation..

Time:09-20

Create a thread in the for loop, how to put the corresponding index of the I pass into the method of thread, because of the for loop will soon end, each thread can only run the index method of parameters,
Have to solve this kind of situation before, after half a year to forget how to solve,,
Help!

CodePudding user response:

Answer questions on your title: multithreaded how to pass parameters? Capture local variables can be completed by means of entrust incoming parameters

Var parameter=123;

Task. Run (()=& gt; {var foo=parameter;//to get parameters});

The Task here. Run and Thread is the same meaning, are open multiple threads, but I recommend using the method of Task, because the Task is a Thread pool

CodePudding user response:

Images that you write is no problem, if you count=1 or length=0

CodePudding user response:

Thank you, have been solved, the previous code generic plus the wrong object, it is no wonder that has been operating with a window, only harm I think one way and didn't preach to
  •  Tags:  
  • C#
  • Related