private static void HashThread(IHashAlgorithm algo, BlockingCollection <string> producerConsumerCollection) { var hashAlgo = algo.CreateHashAlgorithm(); var taskOutputs = new StringBuilder(); int count = 0; while (!producerConsumerCollection.IsCompleted) { string line; try { line = producerConsumerCollection.Take(); } catch (InvalidOperationException) { if (producerConsumerCollection.IsCompleted) { break; } throw; } // Hash that line. byte[] inputBytes = Encoding.ASCII.GetBytes(line); byte[] hash = hashAlgo.ComputeHash(inputBytes); // Convert to hexadecimal. foreach (byte b in hash) { taskOutputs.Append(HexStringTable[b]); } taskOutputs.Append(' '); taskOutputs.AppendLine(line); // Output the hashed values in a batch. if (++count > 10000) { Console.Write(taskOutputs.ToString()); taskOutputs.Clear(); count = 0; } } // Output the last hashed values. Console.Write(taskOutputs.ToString()); }
private static void HashThread(IHashAlgorithm algo, BlockingCollection<string> producerConsumerCollection) { var hashAlgo = algo.CreateHashAlgorithm(); var taskOutputs = new StringBuilder(); int count = 0; while (!producerConsumerCollection.IsCompleted) { string line; try { line = producerConsumerCollection.Take(); } catch (InvalidOperationException) { if (producerConsumerCollection.IsCompleted) break; throw; } // Hash that line. byte[] inputBytes = Encoding.ASCII.GetBytes(line); byte[] hash = hashAlgo.ComputeHash(inputBytes); // Convert to hexadecimal. foreach (byte b in hash) { taskOutputs.Append(HexStringTable[b]); } taskOutputs.Append(' '); taskOutputs.AppendLine(line); // Output the hashed values in a batch. if (++count > 10000) { Console.Write(taskOutputs.ToString()); taskOutputs.Clear(); count = 0; } } // Output the last hashed values. Console.Write(taskOutputs.ToString()); }