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;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)