473,406 Members | 2,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Help for VBnet Thread

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
1 962
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
4
by: Rookie | last post by:
I need to display several columns of numbers in a textbox. I wish to display the columns with the decimal point position aligned vertically. I have found that the # digit placeholders do not...
3
by: Schorschi | last post by:
The following code works fine until I check the .CanDeserialize flag The exact same code in C# works, but in VB .NET? AUGH! HELP! ---------------------------------- Public Function...
1
by: KT | last post by:
Do we have any idea how long VBNet is going to be supported? Being a hobbyist VB6 user I am only interested in creating windows based applications and have no need for web services, asp etc. I...
2
by: Thief_ | last post by:
I am trying to find the sentence for which a particular word exists in and have this expression: (*>)?country.+?(<|\.) In this example, I want it to find all sentences with the word "country"...
2
by: pbd22 | last post by:
Hi. I am getting the error: "Thread is running or terminated. It cannot restart." It is happening inside a file upload loop where a thread is created for each file (reporting bytes). After the...
0
by: SapAddonDeveloper | last post by:
Hello, I am writing an add-on using vbnet/c# that runs inside a Sap B1 application. I need to be able to change the input language (little blue white icon on the system tray) on certain...
1
by: dyc | last post by:
Can somebody help? Really need help. I got this sample from internet but there some parts I could not understand well why we have to use the thing for .. Hope can seek some advice through this...
2
by: Michael Kintner | last post by:
Does someone have code for an Access database form that can look at the contents of a directory and display in a form window with options of ICONS, LIST, DETAILED LIST simular to how Windows...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.