Beispiel #1
0
        public void RunInParallel(ICanceleableTask runnable)
        {
            var threadCount = _threadCountCalculationStrategy.GetThreadCount();

            _autoResetEvent = new AutoResetEvent(false);

            for (int i = 0; i < threadCount; i++)
            {
                var thread = new Thread(new TaskRunWrapper(runnable, OnComplete, OnError).Run);
                _threads.TryAdd(thread.ManagedThreadId, thread);
                thread.Start(_cancellationTokenSource.Token);
            }
        }
Beispiel #2
0
 public TaskRunWrapper(ICanceleableTask task, Action completeHandler, Action <Exception> errorHandler)
 {
     _task            = task;
     _errorHandler    = errorHandler ?? throw new ArgumentNullException(nameof(errorHandler));
     _completeHandler = completeHandler ?? throw new ArgumentNullException(nameof(completeHandler));
 }