是否有可能在后台工作者中拥有多个DoWorks? [英] Is it possible to have multiple DoWorks in a background worker?

查看:152
本文介绍了是否有可能在后台工作者中拥有多个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和等等?

推荐答案

你有多个DoWork方法吗?没有。



我认为解决这个问题的方法相当明显。使用多个BackgroundWorkers,每个都有自己的DoWork方法。
Can you have multiple DoWork methods? No.

I think the way to fix this is rather obvious. Use multiple BackgroundWorkers, each with it's own DoWork method.


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆