[VB.Net] How to make multi threading w/ cross calls? Lets say i have to wait 500ms to run this code again but i wont use Sleep(500) but instead it will make another thread for that code here so there we're 2 threads running this code Code: For counter = 0 To DataGridView1.Rows.Count - 1 Select Case DataGridView1.Rows(counter).Cells(8).Value Case 1 DataGridView1.Rows(counter).Cells(10).Value = Integer.Parse(DataGridView1.Rows(counter).Cells(10).Value) + 1 Dim x As New TimeSpan(0, 0, DataGridView1.Rows(counter).Cells(10).Value) DataGridView1.Rows(counter).Cells(4).Value = x.ToString DataGridView1.Rows(counter).Cells(5).Value = Format((Decimal.Parse(ini.ReadString("per15minbasis")) / 60) * DataGridView1.Rows(counter).Cells(10).Value, "0.00") & " Pesos" If DataGridView1.Rows(counter).Cells(10).Value >= DataGridView1.Rows(counter).Cells(9).Value + Integer.Parse(ini.ReadString("timedelay")) Then DataGridView1.Rows(counter).Cells(10).Value = 0 DataGridView1.Rows(counter).Cells(9).Value = 0 DataGridView1.Rows(counter).Cells(8).Value = 0 Threading.Thread.Sleep(100) Send("state:" & ini.ReadString("timekill"), DataGridView1.Rows(counter).Cells(11).Value) End If End Select Next
just an example from one of my programs Code: Public Delegate Sub UpdateMenuCallback(ByVal status As Boolean, ByVal size As ULong, ByVal Inum As ULong) Me.Invoke(New UpdateMenuCallback(AddressOf Me.UpdateMenu), New Object() {False, SH.i64Size, SH.i64NumItems}) Public Sub UpdateMenu(ByVal status As Boolean, ByVal size As ULong, ByVal Inum As ULong) Dim ch As MenuItem = notificationMenu.MenuItems.Item(3).MenuItems.Item(1) ch.Text = "Empty Recycle Bin: Items:=" & Inum & ". Size:=" & SetBytes(size) ch.Enabled = status End Sub Ok the Me.Invoke is the code you place in the second thread to it tells the application that you need to run the sub UpdateMenu with the parameters the UpdateMenu will the update your UI with the object values you need to display