I have a code for Visual Basic programming language that reads byte array from files, I use that code:
Imports System.IO
Imports System.Threading
Public Class Form1
Dim thread As New Thread(AddressOf RW_EXE)
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
With OpenFileDialog1
If .ShowDialog() = Windows.Forms.DialogResult.OK Then
thread.IsBackground = True
Control.CheckForIllegalCrossThreadCalls = False
thread.Start()
End If
End With
End Sub
Sub RW_EXE()
RichTextBox1.Text = ""
Dim FS As New FileStream(OpenFileDialog1.FileName, FileMode.Open, FileAccess.Read)
Dim BS As New BinaryReader(FS)
Dim x As Integer = BS.BaseStream.Position
Dim y As Integer = BS.BaseStream.Length
Dim s As String = ""
ProgressBar3.Maximum = y
While x < y
RichTextBox1.Text &= BS.ReadByte.ToString("X") & " "
ProgressBar3.Value = x
x += 10
End While
RichTextBox1.Text = s
FS.Close()
BS.Close()
thread.Abort()
End Sub
That code does it's job well, but I have one problem, It's very slow, it takes big time to read array bytes from files with size of 100 KB and from bigger files.
Please, help.
Thanks for attention.
Thread.RichEditBox.Textwith every single byte, which is extremely slow. Fourth, you're updating theProgressBarwith every single byte (with a large file, you're doing many updates that will cause no visible change, which means you're doing it for absolutely no reason). Finally, you're clearingRichEditBox.Textby setting it to an empty string (s), so why put the text in the richtextbox in the first place?Control.CheckForIllegalCrossThreadCalls = Falseand do the threading properly. That line only hides problems.