Alright so I will try and make this as simple a possible. For this example, there is listbox1, and button3.
There are 10 items in listbox1 (A-T).
The user selects 1 item and then clicks Button3.
Button3 Starts the background worker.
BackgroundWorker3 downloads a file using My.Computer.Network.DownloadFile ("google.com/" & ItemSelection)
ItemSelection is "Dim(ed)" in the background worker -> Dim ItemSelection = ListBox1.SelectedItem
So what should happen is, the user selects the Item, The user clicks "go", the background worker attempts to download from (if selection was "A") google.com/A.
But what actually happens is, I get a "cross thread" error about how I cannot reference back to ItemSelection because it is not being used on the thread is was created on.
Example Code-
...Code:Imports System.IO Imports Shell32 Public Class Form1 Dim Desktop As String = My.Computer.FileSystem.SpecialDirectories.Desktop Dim Username As String = Environment.UserName Private P As Integer
...Code:Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click BackgroundWorker3.RunWorkerAsync() End Sub
The ErrorCode:Private Sub BackgroundWorker3_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker3.DoWork Dim ItemSelection = ListBox1.SelectedItem My.Computer.Network.DownloadFile("http://google.com/" & ItemSelection, Desktop) End Sub
Any help would be great!
Hunter





Reply With Quote