Parallel.For(0, loopCount, parallelOptions, loopno => { for (int i = 0; i < tDSInput.Tables[0].Rows.Count; i++) { ////////Here i want to chk the CPU usage (if cpu usage is > 95%) then stop all running threads else normal execution. var locker = new object(); Monitor.Enter(locker); try { var tasks = Task.Factory.StartNew(() => ABC(),TaskCreationOptions.LongRunning) .ContinueWith(t => DEF(), TaskContinuationOptions.ExecuteSynchronously) .ContinueWith(t => GHI(), TaskContinuationOptions.ExecuteSynchronously) .ContinueWith(t => JKL(), TaskContinuationOptions.ExecuteSynchronously) .... .... .... .... .... .... .ContinueWith(t => XYZ(), TaskContinuationOptions.ExecuteSynchronously) Task.WaitAll(tasks); } finally { Monitor.Exit(locker); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)