Пример #1
0
        public void Start()
        {
            var readThread = new Thread(Read)
            {
                Name = "Read thread"
            };

            readThread.Start();

            var processingThreads = new List <Thread>();

            for (var i = 0; i < Environment.ProcessorCount; i++)
            {
                var processingThread = new Thread(Processing)
                {
                    Name = $"Processing {i}"
                };
                processingThreads.Add(processingThread);
                processingThread.Start();
            }

            var writeThread = new Thread(Write)
            {
                Name = "Write thread"
            };

            writeThread.Start();

            readThread.Join();
            _processingBuffer.CloseQueue();

            foreach (var processingThread in processingThreads)
            {
                processingThread.Join();
            }
            _writingBuffer.Close();

            writeThread.Join();

            if (_error != null)
            {
                throw _error;
            }
        }