Remember that UI updation is always done on the parent thread itself. You'd need to use the Invoke methods to make sure of this.
This is what the error is reminding you of... that you are violating the cardinal rule of Multithreaded Win32 apps. On Jun 16, 8:55 pm, yogs <[email protected]> wrote: > Hi, > I am trying to print the numbers in a listbox control using a thread, > but its giving an error "Cross-thread operation not valid". > Please help me to resolve this error. > > Thanks > ........... > VB.NET code: > > Imports System.Threading.Thread > Public Class Form1 > Inherits System.Windows.Forms.Form > Dim thread1 As System.Threading.Thread > > Public Sub addItems() > > Dim ii As Integer > Dim no As Integer > no = 2 > ' add numbers to listbox > For ii = 1 To 10 > ListBox1.Items.Add(no) > no *= 2 > Next ii > > End Sub > > Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles MyBase.Load > > thread1 = New System.Threading.Thread(AddressOf Me.addItems) > thread1.IsBackground = True > thread1.Start() > > End Sub > > End Class
