public void Start(object buffer) { ByteBufferOnArray byteBuffer = (ByteBufferOnArray)buffer; while (byteBuffer.HasAlmostOneChunk()) { processedChunksCount = 0; dict.Clear(); processingThreads.Clear(); for (int i = 0; i < threadCount; i++) { if (byteBuffer.HasAlmostOneChunk()) { try { byte[] chunk = byteBuffer.GetChunk(); long number = currentChunk; Thread thread = new Thread(() => ProcessChunk(chunk, number)); processingThreads.Add(thread); thread.Start(); } catch (Exception ex) { Console.WriteLine(ex.Message + "\n" + ex.StackTrace); } processedChunksCount++; currentChunk++; } } foreach (Thread thread in processingThreads) { thread.Join(); } int id = 0; foreach (byte[] chunk in GetOrderedChunks()) { ConsoleOutputter.Write(currentChunk - processedChunksCount + id, chunk); id++; } } if (byteBuffer.NotProcessedBytesCount() > 0) { ConsoleOutputter.Write(currentChunk, hasher.ComputeHash(byteBuffer.GetLastChunk())); } }