public void TestJob(Pooler.Base pool) { int i = 0; lock (this._taskBeginCounterLock) { i = this._taskBeginCounter; this._taskBeginCounter++; } // some dummy computation to execute long nthPrime; // find prime numbers for first time nthPrime = this.TestJobToFindPrimeNumbers(1000); // wait for sime time if there is set in pool any pool.Pause(); if (Main.N_EXCEPTIONS > 1) { if (i % 3 == Main.N_EXCEPTIONS) { throw new Exception($"Exception modulo " + Main.N_EXCEPTIONS); } } // find prime numbers for second time nthPrime = this.TestJobToFindPrimeNumbers(1000); }
private static void _taskDoneHandler(Pooler.Base pool, TaskDoneEventArgs poolerTaskDoneEventArgs) { lock (Program._taskDoneCounterLock) { Program._taskDoneCounter++; Program._currentlyRunningTasksCounter = poolerTaskDoneEventArgs.RunningTasksCount; } }
private void _taskDoneHandler(Pooler.Base pool, TaskDoneEventArgs poolTaskDoneEventArgs) { lock (this._taskDoneCounterLock) { this._taskDoneCounter++; this._currentlyRunningTasksCounter = poolTaskDoneEventArgs.RunningTasksCount; } }
private static void _allDoneHandler(Pooler.Base pool, AllDoneEventArgs poolAllDoneEventArgs) { Program._peakThreadsCounter = poolAllDoneEventArgs.PeakThreadsCount; if (poolAllDoneEventArgs.Exceptions.Count != Program._taskExceptionCounter) { throw new Exception("Exceptions counter is wrong!"); } Program._report(); }
private static void _testTask(Pooler.Base pool) { var i = 0; lock (Program._taskBeginCounterLock) { i = Program._taskBeginCounter; Program._taskBeginCounter++; } Thread.Sleep(10); if (i % 3 == 0) { throw new Exception($"Exception modulo 3"); } }
private void _allDoneHandler(Pooler.Base pool, AllDoneEventArgs poolAllDoneEventArgs) { this._peakThreadsCounter = poolAllDoneEventArgs.PeakThreadsCount; if (poolAllDoneEventArgs.Exceptions.Count != this._taskExceptionCounter) { throw new Exception("Exceptions counter is wrong!"); } this._peakThreadsCounter = poolAllDoneEventArgs.PeakThreadsCount; this._currentlyRunningTasksCounter = 0; this.BackgroundReporting(); this._reportThread.Abort(); //poolAllDoneEventArgs.ExecutedTasksCount //poolAllDoneEventArgs.NotExecutedTasksCount }
private static void _initParallelThreadsPool() { Parallel pool = Parallel.CreateNew(Program.RUNNING_THREADS_IN_TEST_SIMULTANEOUSLY); pool.AllDone += Program._allDoneHandler; pool.TaskDone += Program._taskDoneHandler; pool.TaskException += Program._threadExceptionHandler; for (int i = 0; i < Program.RUNNING_THREADS_IN_TEST_TOTAL; i++) { pool.Add(new Pooler.TaskDelegate(Program._testTask), false, ThreadPriority.Lowest); } Thread.CurrentThread.Priority = ThreadPriority.Highest; Program._stopWatch = Stopwatch.StartNew(); Program._reportTimer = new System.Threading.Timer(delegate { Thread.CurrentThread.Priority = ThreadPriority.Highest; Program._report(); }, null, 0, 200); Program._pool = pool; }
private static void _initRepeaterThreadsPool() { Repeater pool = Repeater.CreateNew( Program.RUNNING_THREADS_IN_TEST_SIMULTANEOUSLY, Program.RUNNING_THREADS_IN_TEST_TOTAL ); pool.AllDone += Program._allDoneHandler; pool.TaskDone += Program._taskDoneHandler; pool.TaskException += Program._threadExceptionHandler; pool.Set(new Pooler.TaskDelegate(Program._testTask), false, ThreadPriority.Lowest, false); Thread.CurrentThread.Priority = ThreadPriority.Highest; Program._stopWatch = Stopwatch.StartNew(); Program._reportTimer = new System.Threading.Timer(delegate { Thread.CurrentThread.Priority = ThreadPriority.Highest; Program._report(); }, null, 0, 200); Program._pool = pool; }
private static void _threadExceptionHandler(Pooler.Base pool, ExceptionEventArgs poolThreadExceptionEventArgs) { lock (Program._taskExceptionCounterLock) { Program._taskExceptionCounter++; } }
private void _threadExceptionHandler(Pooler.Base pool, ExceptionEventArgs poolThreadExceptionEventArgs) { lock (this._taskExceptionCounterLock) { this._taskExceptionCounter++; } }