Hi all guys, i want to increase a label in Form1 using a thread, but it say "Cross-thread operation not valid: Control 'Label1' accessed from a thread other than the thread it was created on.", how can i access to the label from a thread?
VB Code:
Imports System.Threading Public Class Form1 Dim par As Thread Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click par.Start() End Sub Public Sub New() ' This call is required by the Windows Form Designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. par = New Thread(AddressOf runs) End Sub Sub runs() Dim i As Long = 0 While True For i = 0 To 300 i += 1 label1.Text = i Next End While End Sub End Class




Reply With Quote