I want to calculate few different hashes of a file in parallel in order to increase the performance of my application.
I have the following code:
Dim lThreads As List(Of Thread) = New List(Of Thread)()
For i = 0 To algorithms.Count - 1
Dim index = i
Dim t As Thread = New Thread(
New ThreadStart(Sub()
Dim reader2 as System.IO.FileStream = reader
reader2.position = 0
listDigestvalue(index) = CalculateHash(algorithm, listReader(index))
End Sub))
t.Name = "Thread of algorithm: " + shortnameofalgorithm
t.Start()
lThreads.Add(t)
Next
For i = 0 To lThreads.Count - 1
lThreads(i).Join()
Next
The problem is that for each execution, program doesn´t generate the correct hash of the file.
Is there another way to paralellize these operations.
Thank you in advance.