How to pause and resume the parallel for each based on number of thread executed.
My requirement is I have a N time of loop count in each iteration I have request one API call .the max number of request is 2. i have to wait for any one the request is finished then i have to iterate next one. Please suggest how to pause and resume the parallel foreach loop
My code below,
var MaxConcurrency = new ParallelOptions() { MaxDegreeOfParallelism = 2 };
Parallel.ForEach(ListofWI, MaxConcurrency, async (CurrentWI) =>
{
ServiceInput objServiceInput = new ServiceInput { Login = newLoginDetails,
Connectioninfo = newConnectionInfo, WorkItem = CurrentWI.Value,
Services = mlserviceList };
String Inputstring = JsonConvert.SerializeObject(objServiceInput,
Newtonsoft.Json.Formatting.Indented);
WIuploader newUpload = new WIuploader(logininfo, CurrentWI.Value, newConnectionInfo);
Progress<WorkItem> report = new Progress<WorkItem>(workItemUpdate =>
{
});
workItem = await threadingtask.Task.Run(() => newUpload.Execute(report));
StatusofWorkitem.Add(workItem);
});