Click here to Skip to main content
15,891,785 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a small piece of code to load images from specified directory and create image-checkbox dynamically with them and add to a FlowLayoutPanel. Now I want to useelp threading to load images faster. I am a newbie and don't know how to use threading. Can anybody help me?

My Code:

C#
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim dlg As New FolderBrowserDialog
        If dlg.ShowDialog = DialogResult.OK Then
            TextBox1.Text = dlg.SelectedPath
            For Each item As String In Directory.GetFiles(TextBox1.Text, "*.jpg")
                Dim checkBox As New CheckBox
                Dim original As Image = Image.FromFile(item)
                Dim resized As Image = ResizeImage(original, New Size(78, 78))
                original.Dispose()
                checkBox.Size = New Size(117, 109)
                checkBox.Text = (Path.GetFileName(item))
                checkBox.Image = resized
                checkBox.BackColor = Color.Gray
                checkBox.ForeColor = Color.White
                checkBox.TextAlign = ContentAlignment.BottomCenter
                AddHandler checkBox.CheckedChanged, AddressOf myhandler2
                FlowLayoutPanel1.Controls.Add(checkBox)
            Next
        End If
    End Sub


What I have tried:

I do not try anything. As I don't have any idea on how to do that.
Posted
Updated 19-Jul-16 3:20am
Comments
F-ES Sitecore 19-Jul-16 9:34am    
One issue you might have is that you can read the files using multi-threading but you won't be able to update the GUI using multi-threading as the GUI runs on a single thread. So if multi-threading helps you depends on if the bottle neck is reading the images or updating the UI.

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900