这可能会被标记下来,但如果内存使用不是一个大问题,那么我建议读取整个文件并将这些24字节序列存储在字节数组中(23)。然后使用
Parallel.For
试试这个。。
Imports System.Math
Imports System.IO
Public Class Form1
'create the data array, with just 1 element to start with
'so that it can be resized then you know how many 1024 byte
'chunks you have in your file
Dim DataArray(1)() As Byte
Private Sub ReadByteSequences(pathtoFile As String)
Using fs As New FileStream(pathtoFile, FileMode.Open, FileAccess.Read, FileShare.Read)
'resize the array when you have the file size
ReDim DataArray(CInt(Math.Floor(fs.Length) / 1024))
For i As Long = 0 To fs.Length Step 1024
Dim buffer(23) As Byte
fs.Seek(i, SeekOrigin.Begin)
fs.Read(buffer, 0, 24)
'store each 24 byte sequence in order in the
'DataArray for later processing
DataArray(CInt(Math.Floor(i / 1024))) = buffer
Next
End Using
End Sub
Private Sub ProcessDataArray()
Parallel.For(0, DataArray.Length, Sub(i As Integer)
'do atuff in parallel
End Sub)
End Sub
End Class