Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators/General/Parallel.cs =================================================================== diff -u -r3893 -r4000 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators/General/Parallel.cs (.../Parallel.cs) (revision 3893) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators/General/Parallel.cs (.../Parallel.cs) (revision 4000) @@ -25,8 +25,8 @@ using System.Diagnostics; using System.Threading; using Deltares.DamEngine.Data.Standard.Calculation; -//using Deltares.Standard.Logging; using ThreadState = System.Threading.ThreadState; +//using Deltares.Standard.Logging; namespace Deltares.DamEngine.Calculators.General { @@ -35,16 +35,16 @@ /// public class Parallel { - private static Queue queue = new Queue(); + private static readonly Queue queue = new Queue(); private static TaskDelegate task; private static ProgressDelegate progress; private static int total; private static int executed; - private static List threads = new List(); - private static List processes = new List(); + private static readonly List threads = new List(); + private static readonly List processes = new List(); private static bool stopPressed; private static bool errorOccured; - private static bool limitToAvailableProcessors = true; + private static readonly bool limitToAvailableProcessors = true; /// /// Runs a number of tasks in parallel. Returns when all tasks have been executed. @@ -95,7 +95,7 @@ task = parallelTask; progress = progressDelegate; - foreach (var argument in list) + foreach (object argument in list) { queue.Enqueue(argument); } @@ -104,7 +104,7 @@ executed = 0; threads.Clear(); - for (int i = 0; i < maxProcesses; i++) + for (var i = 0; i < maxProcesses; i++) { var thread = new Thread(RunTask); threads.Add(thread); @@ -119,7 +119,7 @@ } } - foreach (var thread in threads) + foreach (Thread thread in threads) { thread.Join(); } @@ -151,15 +151,15 @@ { stopPressed = true; - foreach (var process in processes.ToArray()) + foreach (Process process in processes.ToArray()) { if (!process.HasExited) { process.Kill(); } } - foreach (var thread in threads) + foreach (Thread thread in threads) { switch (thread.ThreadState) { @@ -172,6 +172,7 @@ { // ignore } + break; case ThreadState.WaitSleepJoin: thread.Interrupt(); @@ -185,13 +186,13 @@ private static void RunSequential(IList list, TaskDelegate parallelTask, ProgressDelegate progressDelegate) { - for (int i = 0; i < list.Count; i++) + for (var i = 0; i < list.Count; i++) { parallelTask(list[i]); if (progressDelegate != null) { - progressDelegate(Convert.ToDouble(i + 1)/Convert.ToDouble(total)); + progressDelegate(Convert.ToDouble(i + 1) / Convert.ToDouble(total)); } } } @@ -238,6 +239,7 @@ // + e.StackTrace)); ##BKA: replace with some other mechanism!? e = e.InnerException; } + errorOccured = true; } finally @@ -246,7 +248,7 @@ { lock (queue) { - progress(Convert.ToDouble(++executed)/Convert.ToDouble(total)); + progress(Convert.ToDouble(++executed) / Convert.ToDouble(total)); } } }