是否有可能在后台工作者中拥有多个DoWorks

是否有可能在后台工作者中拥有多个DoWorks

本文介绍了是否有可能在后台工作者中拥有多个DoWorks?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            byte[] buffer;
            byte[] oldBuffer;
            int bytesRead;
            int oldBytesRead;
            long size;
            long totalBytesRead = 0;

            using (Stream stream = File.OpenRead((string)e.Argument))
            using (HashAlgorithm hashAlgorithm = SHA1.Create())//MD5.Create())
            {
                size = stream.Length;
                buffer = new byte[4096];
                bytesRead = stream.Read(buffer, 0, buffer.Length);
                totalBytesRead += bytesRead;
                do
                {
                    oldBytesRead = bytesRead;
                    oldBuffer = buffer;

                    buffer = new byte[4096];
                    bytesRead = stream.Read(buffer, 0, buffer.Length);

                    totalBytesRead += bytesRead;

                    if (bytesRead == 0)
                    {
                        hashAlgorithm.TransformFinalBlock(oldBuffer, 0, oldBytesRead);
                    }
                    else
                    {
                        hashAlgorithm.TransformBlock(oldBuffer, 0, oldBytesRead, oldBuffer, 0);
                    }

                    BackgroundWorker.ReportProgress((int)((double)totalBytesRead * 100 / size));
                } while (bytesRead != 0);
                e.Result = hashAlgorithm.Hash;





具有以上的倍数但在md5,sha1,sha256和等等?

推荐答案


这篇关于是否有可能在后台工作者中拥有多个DoWorks?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 12:29