Hi
I am trying to introduce Multithreading in to my program so that the program remains responsive but am getting the error Cross threading operation not valid.
My program will execute a batch file on a list of files that I have added to a ListBox. When the batch file finishes working on the first file in the list box I would like the program to increment a number on a label to show that the batch file has finished working on the file and then move on to the next file in the ListBox.
Here is the code I am working with under a button control:
Here is the code I have under the Test1 sub:
I have been looking on the net and trying my hand at few examples but getting no where. Does anyone know of how are where I need to add cross threading code so that I can add a value to the label; control.
Thanks for your help
I am trying to introduce Multithreading in to my program so that the program remains responsive but am getting the error Cross threading operation not valid.
My program will execute a batch file on a list of files that I have added to a ListBox. When the batch file finishes working on the first file in the list box I would like the program to increment a number on a label to show that the batch file has finished working on the file and then move on to the next file in the ListBox.
Here is the code I am working with under a button control:
Code:
Dim t As Threading.Thread
t = New Threading.Thread(AddressOf Me.Test1)
t.Start()
Here is the code I have under the Test1 sub:
Code:
Dim i As Integer
For i = 0 To ListBox1.Items.Count – 1
oWrite = IO.File.CreateText("c:\verify.bat")
‘Btach file commands
oWrite.Close()
Dim p As Process = New Process
p.StartInfo.FileName = ("c:\verify.bat")
p.StartInfo.UseShellExecute = False
p.StartInfo.CreateNoWindow = True
p.Start()
p.WaitForExit()
Dim down As Integer = Label5.Text + 1
Label5.Text = down
Label5.Refresh()
Next
Thanks for your help