hello,
I am new with vb.net, i tried to code a simple program to understand threading. I have enclosed code here by, when i run the program it stucks after some time. I guess its a problem with timer.
if somebody know please help me sort the problem..thanks
Public try1 As Thread
Public try2 As Thread
Public array1(1000) As Short
Public i, j As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
For i = 0 To 1000
array1(i) = CInt(Int((6 * Rnd()) + 1))
Next
calc()
End Sub
Sub calc()
try1 = New Thread(AddressOf compu)
try2 = New Thread(AddressOf compu1)
try1.Start()
try2.Start()
try2.Join()
End Sub
Sub compu()
ListView1.Items.Clear()
For i = 0 To 1000
ListView1.Items.Add(array1(i))
Next i
End Sub
Sub compu1()
ListView2.Items.Clear()
For i = 0 To 1000
j = array1(i) + j
Next i
ListView2.Items.Add(j)
End Sub
I am new with vb.net, i tried to code a simple program to understand threading. I have enclosed code here by, when i run the program it stucks after some time. I guess its a problem with timer.
if somebody know please help me sort the problem..thanks
Public try1 As Thread
Public try2 As Thread
Public array1(1000) As Short
Public i, j As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
For i = 0 To 1000
array1(i) = CInt(Int((6 * Rnd()) + 1))
Next
calc()
End Sub
Sub calc()
try1 = New Thread(AddressOf compu)
try2 = New Thread(AddressOf compu1)
try1.Start()
try2.Start()
try2.Join()
End Sub
Sub compu()
ListView1.Items.Clear()
For i = 0 To 1000
ListView1.Items.Add(array1(i))
Next i
End Sub
Sub compu1()
ListView2.Items.Clear()
For i = 0 To 1000
j = array1(i) + j
Next i
ListView2.Items.Add(j)
End Sub