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.
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.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




Reply With Quote
