I've found hash calculation only in one method
bgw_Md5_DoWork
; and it's not shown how it's called. The implementation suggests that you call it in a separate non-UI thread. Even though some loop is shown, there is only one object which receives the hash value,
md5_e.Result
. Even if it wasn't outside of the loop, it would be only one. I don't know what do you mean by "all of them", but you are not trying to calculate more than one hash value. If you need more than one hash value, you need some collection which works as a sink for multiple hash values. As a single hash value is array of bytes,
byte []
, the data type for the data holding several hash value should be some collection of arrays of arrays of bytes, or array of array of bytes, which would be less suitable, because you may not know total number of values in advance. This is just one thing you have to do.
Now, let's look at two methods you call in the loop. Even though your code does not comprehensively represent the problem, it's very unlikely that it can be anything but
System.Security.Cryptography.TransformBlock
and
System.Security.Cryptography.TransformFinalBlock
:
https://msdn.microsoft.com/en-us/library/system.security.cryptography.hashalgorithm.transformblock%28v=vs.110%29.aspx[
^],
https://msdn.microsoft.com/en-us/library/system.security.cryptography.hashalgorithm.transformblock%28v=vs.110%29.aspx[
^].
First method places data in output buffer, and the last one simply returns array of bytes. Your buffers are local variables, so you don't keep any data you would collect in output buffer on the method return. As to the second method, you simply ignore its return. No wonder you loose the hash data. So, if you need this data, you should not ignore the return, and need to save it in some data collection(s) object(s) created outside of this function; you will need to pass the collection reference to your method.
Also, if you really use non-UI thread for the operation, you may have some difficulty passing data into and our of the data of your methods called in this thread. For this purpose, look at my
thread wrapper technique I've suggested and widely use. Everything is explained in my past answers:
Change parameters of thread (producer) after it is started[
^],
How to pass ref parameter to the thread[
^],
Classes in list updating in their own thread[
^],
AsyncCallback and Threadings[
^] (with fully operational sample),
MultiThreading in C#[
^].
—SA