Results 1 to 11 of 11

Thread: [Resolved]Thread Pool Download Multiple Files at Once

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2007
    Posts
    9

    Resolved [Resolved]Thread Pool Download Multiple Files at Once

    I'm trying to use the thread pool to download more than one string at a time. But most of the tutorial on threading is in C# or C++ so my knowledge on thread pool is limited.

    Here's what I got so far.
    Code:
    Imports System.Threading
    Imports System.Net
    Imports System.Text.RegularExpressions
    
    Public Class Example
    
        Private sLocation As String
        Private sName As String
        Private GameURL As String
    
        Private Sub Add()
            Dim dFile As New WebClient
            Dim FileStr As String
            FileStr = dFile.DownloadString(sLocation & sName)
            If Regex.IsMatch(FileStr, "(?<=<img src="")(.*?)(?="">)") = False Then Exit Sub
            ListBox1.Items.Add(sLocation & Regex.Match(FileStr, "(?<=<img src="")(.*?)(?="">)").Value)
        End Sub
    
        Private Sub Example_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            For Each FileLoc As String In IO.File.ReadAllLines(Application.StartupPath & "\Location.txt")
                For Each FileName As String In IO.File.ReadAllLines(Application.StartupPath & "\Name.txt")
                    sLocation = FileLoc
                    sName = FileName
                    ThreadPool.QueueUserWorkItem(AddressOf Add)
                Next
            Next
        End Sub
    End Class
    I keep getting an error "Cross-thread operation not valid: Control 'Listbox1' accessed from a thread other than the thread it was created on." And it still seems to be downloading it one by one to me.
    Last edited by SCRN; Sep 2nd, 2009 at 03:16 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width