C Sharp: Difference between revisions

232 bytes added ,  27 November 2019
No edit summary
Line 44: Line 44:
     ManualResetEvent finishedHandle = new ManualResetEvent(false);
     ManualResetEvent finishedHandle = new ManualResetEvent(false);
     for (int i = 0; i < numberOfTasks; i++) {
     for (int i = 0; i < numberOfTasks; i++) {
      // Note that you cannot reuse i here.
      // You can use this trick to put it in a closure
      // Or you can make a closure manually with another anonymous function
      // i.e. (a => { return _=>{ \\ Do stuff here })(a)
       int j = i;
       int j = i;
       ThreadPool.QueueUserWorkItem(_ => {
       ThreadPool.QueueUserWorkItem(_ => {