Example #1
0
        public long RunParallel(int count, object param = null,bool infinite=false)
        {
            var sw = new Stopwatch();

            CyclesCounter = new CounterContainer();
            Exceptions = new LockFreeQueue<Exception>();
            Results = new LockFreeQueue<object>();
            if (count % _maxDegreeOfParallelism != 0) throw new Exception();
            var steps = count / _maxDegreeOfParallelism;
            _runningThreads = _maxDegreeOfParallelism;
            _eventStart = new ManualResetEventSlim(false);

            for (int i = 0; i < _maxDegreeOfParallelism; i++)
            {
                var from = steps * i;
                var to = steps * (i + 1);
                var thread = new Thread(RunTask);
                thread.Start(new Tuple<int, int, object,bool>(from, to, param, infinite));
                _threads.Add(thread);
            }
            sw.Start();
            _eventStart.Set();
            if (_waitForTermination)
            {
                while (CyclesCounter.Counter < count)
                {
                    Thread.Sleep(100);
                }
            }
            else
            {
                return 0;
            }
            sw.Stop();
            return sw.ElapsedMilliseconds;
        }
 public SyncTaskHandlerWithMessageRegistration(string threadName, int waitTimeMs,
     int batchSize = 0, int batchTimeoutMs = 0)
     : base(threadName, waitTimeMs, batchSize, batchTimeoutMs)
 {
     MessagesCount = new CounterContainer();
 }