示例#1
0
        public Marger(int fileCount, WordsCountQueue queue, IWords totalResult, ManualResetEventSlim stopEvent, Action <Exception> applExceptionHandler)
        {
            _fileCount            = fileCount;
            _queue                = queue;
            _totalResult          = totalResult;
            _stopEvent            = stopEvent;
            _applExceptionHandler = applExceptionHandler;
            var innerThread = new Thread(Run)
            {
                Name = "Marger"
            };

            innerThread.Start();
        }
示例#2
0
        public void Execute(IResultSaver saver)
        {
            var queue = new WordsCountQueue();

            _stopEvent = new ManualResetEventSlim(false);
            var marger = new Marger(_fileNamesSource.FileNames.Count, queue, saver, _stopEvent, ApplExceptionHandler);

            foreach (var fileName in _fileNamesSource.FileNames)
            {
                var analizer = new FileAnalizer(fileName, queue, ApplExceptionHandler);
                analizer.Execute();
            }
            // здесь выполнение остановится, пока (marger или exception) не просигнализирует об окончании работы
            _stopEvent.Wait();

            if (_wasException != null)
            {
                throw new ApplicationException("Ошибка в дочернем потоке", _wasException);
            }

            saver.Save();
        }