By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,695 Members | 1,221 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,695 IT Pros & Developers. It's quick & easy.

Help for VBnet Thread

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Gianno,

The purpose of threads is that they run completely asynchrone.

When you need synchronise processes you simple would not use threads.
(Don't forget that threads cost extra process time on single processor
computers and not definitely will affect the time on multiprocessor
computers or hyperthreading processors.).

Cor
Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.