Hi,
My application have two threads that run at the same time.
This is my code
Public WithEvents tww1 As New ThreadWrapp1
Public t1 As New Thread(AddressOf tww1.Ask)
Public WithEvents tww2 As New ThreadWrapp2
Public t2 As New Thread(AddressOf tww2.ask)
Public Class ThreadWrapp1
Public Event Event1
Public Sub Ask()
Try
Do
For i = 2 To 4
' ask status of periferal i
If Condition(i)=True Then
RaiseEvent Event1
End If
Next i
Loop
Catch ex As Exception
MsgBox(Err.Description)
End Try
End Sub
End Class
Public Class ThreadWrapp2
Public Event Event2
Public Sub Ask()
Try
Do
For i = 2 To 4
' ask status of periferal i
If Condition(i)=True Then
RaiseEvent Event2
End If
Next i
Loop
Catch ex As Exception
MsgBox(Err.Description)
End Try
End Sub
End Class
Private Sub tww1_Event1() Handles tww1.Event1
' Manage status
End Sub
Private Sub tww2_Event2() Handles tww2.Event2
' Manage status
End Sub
Sub Main
t2.Start
t1.Start
End Sub
I note that threads switch to each other very accidentally and
casually, I would want they switch regolary. For example,
I note this
ThradWrapp1 (Condition (1))
ThradWrapp1 (Condition (2))
ThradWrapp1 (Condition (3))
ThradWrapp1 (Condition (4))
ThradWrapp1 (Condition (1))
ThradWrapp1 (Condition (2))
ThradWrapp1 (Condition (3))
ThradWrapp1 (Condition (4))
ThradWrapp2 (Condition (1))
ThradWrapp2 (Condition (2))
ThradWrapp1 (Condition (1))
ThradWrapp1 (Condition (2))
ThradWrapp1 (Condition (3))
ThradWrapp1 (Condition (4))
ThradWrapp1 (Condition (1))
ThradWrapp1 (Condition (2))
I wold want this
ThradWrapp1 (Condition (1))
ThradWrapp2 (Condition (1))
ThradWrapp1 (Condition (2))
ThradWrapp2 (Condition (2))
ThradWrapp1 (Condition (3))
ThradWrapp2 (Condition (3))
ThradWrapp1 (Condition (4))
ThradWrapp2 (Condition (4))
ThradWrapp1 (Condition (1))
ThradWrapp2 (Condition (1))
ThradWrapp1 (Condition (2))
ThradWrapp2 (Condition (2))
ThradWrapp1 (Condition (3))
ThradWrapp2 (Condition (3))
ThradWrapp1 (Condition (4))
ThradWrapp2 (Condition (4))
or nearly...
Thanks and sorry my bad English