Exemplo n.º 1
0
        private void HashIt()
        {
            bool earlyEnd = false;

            try
            {
                using (var hasher = SHA256.Create())
                {
                    BlockInfo block;
                    while ((block = _blockPool.GetNext()) != null)
                    {
                        if (_blockPool.manualStop)
                        {
                            earlyEnd = true;
                            break;
                        }

                        var hash       = hasher.ComputeHash(block.bytes);
                        var hashString = string.Join("", hash.Select(x => x.ToString("x2")).ToArray());

                        Console.WriteLine("{0}:{1}", block.index, hashString);
                        _blockPool.ReturnBlock(block);
                    }
                }

                Interlocked.Increment(ref _countOfEndedThreads);

                if (_countOfEndedThreads == _threads.Length - 1)
                {
                    ThreadsCompleted?.Invoke(this, new ThreadsCompletedEventArgs
                    {
                        isBreaked = earlyEnd
                    });
                }
            }
            catch (Exception exc)
            {
                Console.WriteLine("{0}\n{1}", exc.Message, exc.StackTrace);
                Console.ReadKey();
            }
        }