none
Pausing and resuming Parallel.ForEach RRS feed

  • Question

  • I need at some condition to be able pause Parallel.ForEach.

    If some condition happened, I need to wait until all already running threads complete, then perform some action the continue foreach execution

    Parallel.ForEach(mAFGuidList,               
     newParallelOptions { MaxDegreeOfParallelism = parallelDegree },
    
     ( m , state)=>{
    //-------------------------------
    
     
    Interlocked.Increment(refcallCount);
                            
    
          if(callCount % 500== 0)
    
           {
    
             1. Pause Execution and wait antill started earlier threads are 
             2. Prform some action
    
             3. Resume execution
    
      }
    
    //----------------------------
    
    
        DoSomeWork();
    
     
    
      }
    

    Can this be done?


    • Edited by YuriKPMG Tuesday, January 2, 2018 7:07 PM
    Tuesday, January 2, 2018 7:04 PM

All replies