473,395 Members | 2,796 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,395 software developers and data experts.

Multiple event Args in VB 2005

Can anyone tell me if its possible to do multiple event args in vb.net?
Oct 30 '08 #1
27 2077
Yes you can

if you mean with that a event with a argument signature of (n) elements

like this for instance

Public Event eHelloWorld(ByVal a As Date, ByVal b As String, ByVal c As
Integer, ByVal d As Object, ByVal e As System.EventArgs)
just declare it with the wanted arguments this can be value types or
reference types
hth

Michel Posseth [MCP]

"cmdolcet69" <co************@hotmail.comschreef in bericht
news:85**********************************@d45g2000 hsc.googlegroups.com...
Can anyone tell me if its possible to do multiple event args in vb.net?
Oct 30 '08 #2
Yes, what have you tried that doesn't work ?

That said, usually the signature is always the sender and another argument
using a class type that allows to expose whatever members are needed so my
personal preference would be likely to stick to this convention for
consistency unless I find some strong reason to do otherwise.

IMO there is more behind your question. You may want to provide a bit more
details...

--
Patrice

"cmdolcet69" <co************@hotmail.coma écrit dans le message de groupe
de discussion :
85**********************************...oglegroups.com...
Can anyone tell me if its possible to do multiple event args in vb.net?

Oct 30 '08 #3
"cmdolcet69" <co************@hotmail.comschrieb
Can anyone tell me if its possible to do multiple event args in
vb.net?
Is "multiple event args" a term I should know? If not, what's it's meaning?
Armin
Oct 30 '08 #4
On Oct 30, 8:03*am, "Michel Posseth" <m...@posseth.comwrote:
Yes you can

if you mean with that a event with a argument signature of (n) elements

like this for instance

Public Event eHelloWorld(ByVal a As Date, ByVal b As String, ByVal c As
Integer, ByVal d As Object, ByVal e As System.EventArgs)

just declare it with the wanted arguments this can be value types or
reference types

hth

Michel Posseth [MCP]

"cmdolcet69" <colin_dolce...@hotmail.comschreef in berichtnews:85**********************************@d 45g2000hsc.googlegroups.com...
Can anyone tell me if its possible to do multiple event args in vb.net?
Ok so the sub StartWorkerThreadDualDSI1 is suppose to create (2) com
ports so that I can read reading from (2) sources at the same
time….currently this only reads one source at a time…. On the bottom
of the sub I create the two COM Ports currentserial and currentserial2
then it goes into the DoDualDSIWorkCOM! Sub and passing in only the e
argument for the first COM port my question is how can I pass a second
e argument into the DoDualDSIWorkCOM1? Also while in that sub it
calls the sub GetDSIInputCOM1 the serialport is only being passed COM1
and never COM 2 how can I get both COM’s to be passed in?????
Public Sub StartWorkerThreadDualDSI1(ByVal gageType As String)
Dim expectedBaudRate As String = "57600"
Select Case gageType
Case "DSI"
AddHandler dataBackgroundWorker.DoWork, AddressOf
DoDualDSIWorkCOM1
AddHandler dataBackgroundWorker.RunWorkerCompleted,
AddressOf DualDSIWorkComplete
expectedBaudRate = "9600"

End Select
currentSerial = GetSerialPortUsed(1)
currentSerial2 = GetSerialPortUsedCOM2(2)
ChangeCOMBaudRateIfNecessary(expectedBaudRate)
dataBackgroundWorker.RunWorkerAsync(New Object()
(currentSerial})
dataBackgroundWorker2.RunWorkerAsync(New Object()
{currentSerial2})
Me.tmrBackgroundWorker.Enabled = True
Me.tmrBackgroundWorker2.Enabled = True


Private Sub DoDualDSIWorkCOM1(ByVal sender As Object, ByVal e As
DoWorkEventArgs)
Try
Dim args() As Object = e.Argument
Dim intloop As Integer
CType(args(0), IO.Ports.SerialPort).DiscardInBuffer()
muxClass.GetDualDSIInputCOM1(CType(args(0),
IO.Ports.SerialPort))
Catch ex As Exception
tListener.AddMethodError(ex)
End Try
End Sub

Public Sub GetDualDSIInputCOM1(ByVal serialPort As
IO.Ports.SerialPort)
Dim intloop As Integer
Try
serialPort.ReadTimeout = 500
serialPort.DiscardInBuffer()

Dim strDataCOM1 As String = String.Empty
If Not serialPort.IsOpen Then
strDataCOM1 = String.Empty
Else
strDataCOM1 = serialPort.ReadLine
End If
If strDataCOM1.Length 0 Then
COM1Active = 1
Dim tempArray() As String
strDataCOM1 = strDataCOM1.Replace(vbCrLf,
vbTab).Replace(Chr(26), "").Replace(Chr(12), "").Replace(Chr(13), "")
'parses out the information gathered from the COM port
to a temp location
tempArray = Split(strDataCOM1, vbTab)

If serialPort.BaudRate = 9600 Then
DSICollector = "585 Plus"
Get585PlusData(tempArray)
Else
DSICollector = "501/440"
Get501Data(tempArray)
End If
End If

Catch tex As TimeoutException
'do nothing as this will happen while waiting
Catch ioError As System.IO.IOException
'do nothing as this will occur sometimes when closing the
thread
Catch ex As Exception
tListener.AddMethodError(ex)
End Try
End Sub
Oct 30 '08 #5
"cmdolcet69" <co************@hotmail.comschrieb
AddHandler dataBackgroundWorker.DoWork, AddressOf
DoDualDSIWorkCOM1
In the code you posted, I don't see where you add the handler to
dataBackgroundWorker2.DoWork:

AddHandler dataBackgroundWorker2.DoWork, AddressOf DoDualDSIWorkCOM1

Can this be the actual problem? A general answer to your question: If the
event is defined not by yourself, you can not change the number of
arguments. The event handler must have the same number of arguments.

Armin
Oct 30 '08 #6
On Oct 30, 8:55*am, "Armin Zingler" <az.nos...@freenet.dewrote:
"cmdolcet69" <colin_dolce...@hotmail.comschrieb
* * * * * * * *AddHandler dataBackgroundWorker.DoWork, AddressOf
DoDualDSIWorkCOM1

In the code you posted, I don't see where you add the handler to
dataBackgroundWorker2.DoWork:

AddHandler dataBackgroundWorker2.DoWork, AddressOf DoDualDSIWorkCOM1

Can this be the actual problem? A general answer to your question: If the
event is defined not by yourself, you can not change the number of
arguments. The event handler must have the same number of arguments.

Armin
Ok sorry i did make a mistake in the first sub and have now added the
handler to dataBackgroundWorker2 however how do i add this to the
DodualDSIWorkerCOM1 Sub ? how can I pass in the values of the second
databackgroundworker
?
Oct 30 '08 #7
"cmdolcet69" <co************@hotmail.comschrieb
On Oct 30, 8:55 am, "Armin Zingler" <az.nos...@freenet.dewrote:
"cmdolcet69" <colin_dolce...@hotmail.comschrieb
AddHandler dataBackgroundWorker.DoWork, AddressOf
DoDualDSIWorkCOM1

In the code you posted, I don't see where you add the handler to
dataBackgroundWorker2.DoWork:

AddHandler dataBackgroundWorker2.DoWork, AddressOf DoDualDSIWorkCOM1

Can this be the actual problem? A general answer to your question: If the
event is defined not by yourself, you can not change the number of
arguments. The event handler must have the same number of arguments.

Armin
Ok sorry i did make a mistake in the first sub and have now added the
handler to dataBackgroundWorker2 however how do i add this to the
DodualDSIWorkerCOM1 Sub ? how can I pass in the values of the second
databackgroundworker
?

You wrote:

dataBackgroundWorker.RunWorkerAsync(New Object() (currentSerial})
dataBackgroundWorker2.RunWorkerAsync(New Object() {currentSerial2})

You already use the first port with the first BGW and the second port with
the second BGW. Consequently, inside DoDualDSIWorkCOM1, args(0) is the first
or the second port. It is the first port if the method ist executed in the
1st BGW and the 2nd port if executed in the 2nd BGW. So, I think there is no
problem (in this part).
Armin

Oct 30 '08 #8
On Oct 30, 9:46*am, "Armin Zingler" <az.nos...@freenet.dewrote:
"cmdolcet69" <colin_dolce...@hotmail.comschrieb
On Oct 30, 8:55 am, "Armin Zingler" <az.nos...@freenet.dewrote:
"cmdolcet69" <colin_dolce...@hotmail.comschrieb
AddHandler dataBackgroundWorker.DoWork, AddressOf
DoDualDSIWorkCOM1
In the code you posted, I don't see where you add the handler to
dataBackgroundWorker2.DoWork:
AddHandler dataBackgroundWorker2.DoWork, AddressOf DoDualDSIWorkCOM1
Can this be the actual problem? A general answer to your question: If the
event is defined not by yourself, you can not change the number of
arguments. The event handler must have the same number of arguments.
Armin
Ok sorry i did make a mistake in the first sub and have now added the
handler to dataBackgroundWorker2 however how do i add this to the
DodualDSIWorkerCOM1 Sub ? how can I pass in the values of the second
databackgroundworker
?
You wrote:

dataBackgroundWorker.RunWorkerAsync(New Object() (currentSerial})
dataBackgroundWorker2.RunWorkerAsync(New Object() {currentSerial2})

You already use the first port with the first BGW and the second port with
the second BGW. Consequently, inside DoDualDSIWorkCOM1, args(0) is the first
or the second port. It is the first port if the method ist executed in the
1st BGW and the 2nd port if executed in the 2nd BGW. So, I think there isno
problem (in this part).

Armin
ok then how can i have them both running at the same time meaning that
in the sub below: my serialPort is always COM port 1 I need to ahve
COm 1 and COM 2 be open and reading data at the same time.... Is this
possible and does this make sense?

Public Sub GetDualDSIInputCOM1(ByVal serialPort As
IO.Ports.SerialPort)
Dim intloop As Integer
Try
serialPort.ReadTimeout = 500
serialPort.DiscardInBuffer()

Dim strDataCOM1 As String = String.Empty
If Not serialPort.IsOpen Then
strDataCOM1 = String.Empty
Else
strDataCOM1 = serialPort.ReadLine
End If
If strDataCOM1.Length 0 Then
COM1Active = 1
Dim tempArray() As String
strDataCOM1 = strDataCOM1.Replace(vbCrLf,
vbTab).Replace(Chr(26), "").Replace(Chr(12), "").Replace(Chr(13), "")
'parses out the information gathered from the COM port
to a temp location
tempArray = Split(strDataCOM1, vbTab)

If serialPort.BaudRate = 9600 Then
DSICollector = "585 Plus"
Get585PlusData(tempArray)
Else
DSICollector = "501/440"
Get501Data(tempArray)
End If
End If

Catch tex As TimeoutException
'do nothing as this will happen while waiting
Catch ioError As System.IO.IOException
'do nothing as this will occur sometimes when closing the
thread
Catch ex As Exception
tListener.AddMethodError(ex)
End Try
End Sub

Oct 30 '08 #9
"cmdolcet69" <co************@hotmail.comschrieb
You wrote:

dataBackgroundWorker.RunWorkerAsync(New Object() (currentSerial})
dataBackgroundWorker2.RunWorkerAsync(New Object()
{currentSerial2})

You already use the first port with the first BGW and the second
port with the second BGW. Consequently, inside DoDualDSIWorkCOM1,
args(0) is the first or the second port. It is the first port if
the method ist executed in the 1st BGW and the 2nd port if
executed in the 2nd BGW. So, I think there is no problem (in this
part).

Armin

ok then how can i have them both running at the same time meaning
that in the sub below: my serialPort is always COM port 1 I need to
ahve
COm 1 and COM 2 be open and reading data at the same time.... Is
this possible and does this make sense?
Yes, it makes sense. You are already creating two BGWs (background workers),
and you create two SerialPort objects. Each port is handled in it's own
thread. That's the correct approach IMO.

The name of the Sub is confusing because it ends with "COM1", though it
should handle any port. Also the names inside (strDataCOM1, COM1Active).

How do you see that it is always port 1? Maybe because you are watching
variable "COM1Active", which is not local, anywhere else? It pretends to be
COM1 but it isn't always.
Public Sub GetDualDSIInputCOM1(ByVal serialPort As
IO.Ports.SerialPort)
[...]
COM1Active = 1

Armin

Oct 30 '08 #10
On Oct 30, 11:42*am, "Armin Zingler" <az.nos...@freenet.dewrote:
"cmdolcet69" <colin_dolce...@hotmail.comschrieb
You wrote:
dataBackgroundWorker.RunWorkerAsync(New Object() (currentSerial})
dataBackgroundWorker2.RunWorkerAsync(New Object()
{currentSerial2})
You already use the first port with the first BGW and the second
port with the second BGW. Consequently, inside DoDualDSIWorkCOM1,
args(0) is the first or the second port. It is the first port if
the method ist executed in the 1st BGW and the 2nd port if
executed in the 2nd BGW. So, I think there is no problem (in this
part).
Armin
ok then how can i have them both running at the same time meaning
that in the sub below: my serialPort is always COM port 1 I need to
ahve
COm 1 and COM 2 be open and reading data at the same time.... Is
this possible and does this make sense?

Yes, it makes sense. You are already creating two BGWs (background workers),
and you create two SerialPort objects. Each port is handled in it's own
thread. That's the correct approach IMO.

The name of the Sub is confusing because it ends with "COM1", though it
should handle any port. Also the names inside (strDataCOM1, COM1Active).

How do you see that it is always port 1? Maybe because you are watching
variable "COM1Active", which is not local, anywhere else? It pretends to be
COM1 but it isn't always.
Public Sub GetDualDSIInputCOM1(ByVal serialPort As
IO.Ports.SerialPort)
[...]
* * * * * * * * COM1Active = 1

Armin
I see it when i put a watch on the SerialPort variable........what i
want to do is take be able to take both serial port data at the same
time but when I go into the GetDualDSIInputCOM1 it always seems to be
passing in COM1 and not COM1 and COM2 at the same time

Can you help very urgent!!!!
Oct 30 '08 #11
"cmdolcet69" <co************@hotmail.comschrieb
Yes, it makes sense. You are already creating two BGWs (background
workers),
and you create two SerialPort objects. Each port is handled in it's own
thread. That's the correct approach IMO.

The name of the Sub is confusing because it ends with "COM1", though it
should handle any port. Also the names inside (strDataCOM1, COM1Active).

How do you see that it is always port 1? Maybe because you are watching
variable "COM1Active", which is not local, anywhere else? It pretends to
be
COM1 but it isn't always.
Public Sub GetDualDSIInputCOM1(ByVal serialPort As
IO.Ports.SerialPort)
[...]
COM1Active = 1
Armin

I see it when i put a watch on the SerialPort variable........
And then? How do you see the difference? Do they have different property
values that are unique to each instance?
what i
want to do is take be able to take both serial port data at the same
time but when I go into the GetDualDSIInputCOM1 it always seems to be
passing in COM1 and not COM1 and COM2 at the same time

Can you help very urgent!!!!
The two threads do run at the same time. GetDualDSIInputCOM1 is executed
twice, one time in each thread. In thread 1 it handles port 1 and in thread
2 it handles port 2. That's how I expect it to work. I don't see an error in
this regard.

Try this:

In StartWorkerThreadDualDSI1:

dataBackgroundWorker.RunWorkerAsync(New Object() {currentSerial,"port
1"})
dataBackgroundWorker2.RunWorkerAsync(New Object() {currentSerial2,"port
2"})
....
In DoDualDSIWorkCOM1:

Try
Dim args() As Object = e.Argument
Debug.Print(args(1).ToString)
...

Run it without interrupting or setting breakpoints. Do you only get "port 1"
in the debug/output window?
Armin

Oct 30 '08 #12
On Oct 30, 12:23*pm, "Armin Zingler" <az.nos...@freenet.dewrote:
"cmdolcet69" <colin_dolce...@hotmail.comschrieb
Yes, it makes sense. You are already creating two BGWs (background
workers),
and you create two SerialPort objects. Each port is handled in it's own
thread. That's the correct approach IMO.
The name of the Sub is confusing because it ends with "COM1", though it
should handle any port. Also the names inside (strDataCOM1, COM1Active).
How do you see that it is always port 1? Maybe because you are watching
variable "COM1Active", which is not local, anywhere else? It pretendsto
be
COM1 but it isn't always.
Public Sub GetDualDSIInputCOM1(ByVal serialPort As
IO.Ports.SerialPort)
[...]
COM1Active = 1
Armin
I see it when i put a watch on the SerialPort variable........

And then? How do you see the difference? Do they have different property
values that are unique to each instance?
what i
want to do is take be able to take both serial port data at the same
time but when I go into the GetDualDSIInputCOM1 it always seems to be
passing in COM1 and not COM1 and COM2 at the same time
Can you help very urgent!!!!

The two threads do run at the same time. GetDualDSIInputCOM1 is executed
twice, one time in each thread. In thread 1 it handles port 1 and in thread
2 it handles port 2. That's how I expect it to work. I don't see an errorin
this regard.

Try this:

In StartWorkerThreadDualDSI1:

* * dataBackgroundWorker.RunWorkerAsync(New Object() {currentSerial,"port
1"})
* * dataBackgroundWorker2.RunWorkerAsync(New Object() {currentSerial2,"port
2"})
...

In DoDualDSIWorkCOM1:

* * * * Try
* * * * * * Dim args() As Object = e.Argument
* * * * * * Debug.Print(args(1).ToString)
* * * * * * ...

Run it without interrupting or setting breakpoints. Do you only get "port1"
in the debug/output window?

Armin
Running exactly what you say it always hits my error log and give the
following:

Error Information
Error Target - RunWorkerAsync
Error Message - This BackgroundWorker is currently busy and cannot
run multiple tasks concurrently.
Exception Type - System.InvalidOperationException: This
BackgroundWorker is currently busy and cannot run multiple tasks
concurrently.
at System.ComponentModel.BackgroundWorker.RunWorkerAs ync(Object
argument)
at
LMIObjectLibrary.NewRuntimeMethods.StartWorkerThre adDualDSI2(String
gageType) in C:\LMI\Programming\Software\Universal Gage Interface
\Universal Gage Interface 5.0\LMIObjectLibrary
\NewRuntimeMethods.vb:line 2395
at LMIObjectLibrary.NewRuntimeMethods.FindWhatGagesTo Select(Gages
gage) in C:\LMI\Programming\Software\Universal Gage Interface
\Universal Gage Interface 5.0\LMIObjectLibrary
\NewRuntimeMethods.vb:line 860
Stack Trace
at System.ComponentModel.BackgroundWorker.RunWorkerAs ync(Object
argument)
at
LMIObjectLibrary.NewRuntimeMethods.StartWorkerThre adDualDSI2(String
gageType) in C:\LMI\Programming\Software\Universal Gage Interface
\Universal Gage Interface 5.0\LMIObjectLibrary
\NewRuntimeMethods.vb:line 2395
at LMIObjectLibrary.NewRuntimeMethods.FindWhatGagesTo Select(Gages
gage) in C:\LMI\Programming\Software\Universal Gage Interface
\Universal Gage Interface 5.0\LMIObjectLibrary
\NewRuntimeMethods.vb:line 860
System.IO.Ports.SerialPort
System.IO.Ports.SerialPort
System.IO.Ports.SerialPort
System.IO.Ports.SerialPort
System.IO.Ports.SerialPort
System.IO.Ports.SerialPort
System.IO.Ports.SerialPort
System.IO.Ports.SerialPort
System.IO.Ports.SerialPort
System.IO.Ports.SerialPort
Oct 30 '08 #13
On Oct 30, 12:23*pm, "Armin Zingler" <az.nos...@freenet.dewrote:
"cmdolcet69" <colin_dolce...@hotmail.comschrieb
Yes, it makes sense. You are already creating two BGWs (background
workers),
and you create two SerialPort objects. Each port is handled in it's own
thread. That's the correct approach IMO.
The name of the Sub is confusing because it ends with "COM1", though it
should handle any port. Also the names inside (strDataCOM1, COM1Active).
How do you see that it is always port 1? Maybe because you are watching
variable "COM1Active", which is not local, anywhere else? It pretendsto
be
COM1 but it isn't always.
Public Sub GetDualDSIInputCOM1(ByVal serialPort As
IO.Ports.SerialPort)
[...]
COM1Active = 1
Armin
I see it when i put a watch on the SerialPort variable........

And then? How do you see the difference? Do they have different property
values that are unique to each instance?
what i
want to do is take be able to take both serial port data at the same
time but when I go into the GetDualDSIInputCOM1 it always seems to be
passing in COM1 and not COM1 and COM2 at the same time
Can you help very urgent!!!!

The two threads do run at the same time. GetDualDSIInputCOM1 is executed
twice, one time in each thread. In thread 1 it handles port 1 and in thread
2 it handles port 2. That's how I expect it to work. I don't see an errorin
this regard.

Try this:

In StartWorkerThreadDualDSI1:

* * dataBackgroundWorker.RunWorkerAsync(New Object() {currentSerial,"port
1"})
* * dataBackgroundWorker2.RunWorkerAsync(New Object() {currentSerial2,"port
2"})
...

In DoDualDSIWorkCOM1:

* * * * Try
* * * * * * Dim args() As Object = e.Argument
* * * * * * Debug.Print(args(1).ToString)
* * * * * * ...

Run it without interrupting or setting breakpoints. Do you only get "port1"
in the debug/output window?

Armin
Running exactly what you say it always hits my error log and give the
following:

Error Information
Error Target - RunWorkerAsync
Error Message - This BackgroundWorker is currently busy and cannot
run multiple tasks concurrently.
Exception Type - System.InvalidOperationException: This
BackgroundWorker is currently busy and cannot run multiple tasks
concurrently.
at System.ComponentModel.BackgroundWorker.RunWorkerAs ync(Object
argument)
at
LMIObjectLibrary.NewRuntimeMethods.StartWorkerThre adDualDSI2(String
gageType) in C:\LMI\Programming\Software\Universal Gage Interface
\Universal Gage Interface 5.0\LMIObjectLibrary
\NewRuntimeMethods.vb:line 2395
at LMIObjectLibrary.NewRuntimeMethods.FindWhatGagesTo Select(Gages
gage) in C:\LMI\Programming\Software\Universal Gage Interface
\Universal Gage Interface 5.0\LMIObjectLibrary
\NewRuntimeMethods.vb:line 860
Stack Trace
at System.ComponentModel.BackgroundWorker.RunWorkerAs ync(Object
argument)
at
LMIObjectLibrary.NewRuntimeMethods.StartWorkerThre adDualDSI2(String
gageType) in C:\LMI\Programming\Software\Universal Gage Interface
\Universal Gage Interface 5.0\LMIObjectLibrary
\NewRuntimeMethods.vb:line 2395
at LMIObjectLibrary.NewRuntimeMethods.FindWhatGagesTo Select(Gages
gage) in C:\LMI\Programming\Software\Universal Gage Interface
\Universal Gage Interface 5.0\LMIObjectLibrary
\NewRuntimeMethods.vb:line 860
System.IO.Ports.SerialPort
System.IO.Ports.SerialPort
System.IO.Ports.SerialPort
System.IO.Ports.SerialPort
System.IO.Ports.SerialPort
System.IO.Ports.SerialPort
System.IO.Ports.SerialPort
System.IO.Ports.SerialPort
System.IO.Ports.SerialPort
System.IO.Ports.SerialPort
Oct 30 '08 #14
On Oct 30, 12:23*pm, "Armin Zingler" <az.nos...@freenet.dewrote:
"cmdolcet69" <colin_dolce...@hotmail.comschrieb
Yes, it makes sense. You are already creating two BGWs (background
workers),
and you create two SerialPort objects. Each port is handled in it's own
thread. That's the correct approach IMO.
The name of the Sub is confusing because it ends with "COM1", though it
should handle any port. Also the names inside (strDataCOM1, COM1Active).
How do you see that it is always port 1? Maybe because you are watching
variable "COM1Active", which is not local, anywhere else? It pretendsto
be
COM1 but it isn't always.
Public Sub GetDualDSIInputCOM1(ByVal serialPort As
IO.Ports.SerialPort)
[...]
COM1Active = 1
Armin
I see it when i put a watch on the SerialPort variable........

And then? How do you see the difference? Do they have different property
values that are unique to each instance?
what i
want to do is take be able to take both serial port data at the same
time but when I go into the GetDualDSIInputCOM1 it always seems to be
passing in COM1 and not COM1 and COM2 at the same time
Can you help very urgent!!!!

The two threads do run at the same time. GetDualDSIInputCOM1 is executed
twice, one time in each thread. In thread 1 it handles port 1 and in thread
2 it handles port 2. That's how I expect it to work. I don't see an errorin
this regard.

Try this:

In StartWorkerThreadDualDSI1:

* * dataBackgroundWorker.RunWorkerAsync(New Object() {currentSerial,"port
1"})
* * dataBackgroundWorker2.RunWorkerAsync(New Object() {currentSerial2,"port
2"})
...

In DoDualDSIWorkCOM1:

* * * * Try
* * * * * * Dim args() As Object = e.Argument
* * * * * * Debug.Print(args(1).ToString)
* * * * * * ...

Run it without interrupting or setting breakpoints. Do you only get "port1"
in the debug/output window?

Armin
Running exactly what you say it always hits my error log and give the
following:

Error Information
Error Target - RunWorkerAsync
Error Message - This BackgroundWorker is currently busy and cannot
run multiple tasks concurrently.
Exception Type - System.InvalidOperationException: This
BackgroundWorker is currently busy and cannot run multiple tasks
concurrently.
at System.ComponentModel.BackgroundWorker.RunWorkerAs ync(Object
argument)
at
LMIObjectLibrary.NewRuntimeMethods.StartWorkerThre adDualDSI2(String
gageType) in C:\LMI\Programming\Software\Universal Gage Interface
\Universal Gage Interface 5.0\LMIObjectLibrary
\NewRuntimeMethods.vb:line 2395
at LMIObjectLibrary.NewRuntimeMethods.FindWhatGagesTo Select(Gages
gage) in C:\LMI\Programming\Software\Universal Gage Interface
\Universal Gage Interface 5.0\LMIObjectLibrary
\NewRuntimeMethods.vb:line 860
Stack Trace
at System.ComponentModel.BackgroundWorker.RunWorkerAs ync(Object
argument)
at
LMIObjectLibrary.NewRuntimeMethods.StartWorkerThre adDualDSI2(String
gageType) in C:\LMI\Programming\Software\Universal Gage Interface
\Universal Gage Interface 5.0\LMIObjectLibrary
\NewRuntimeMethods.vb:line 2395
at LMIObjectLibrary.NewRuntimeMethods.FindWhatGagesTo Select(Gages
gage) in C:\LMI\Programming\Software\Universal Gage Interface
\Universal Gage Interface 5.0\LMIObjectLibrary
\NewRuntimeMethods.vb:line 860
System.IO.Ports.SerialPort
System.IO.Ports.SerialPort
System.IO.Ports.SerialPort
System.IO.Ports.SerialPort
System.IO.Ports.SerialPort
System.IO.Ports.SerialPort
System.IO.Ports.SerialPort
System.IO.Ports.SerialPort
System.IO.Ports.SerialPort
System.IO.Ports.SerialPort
Oct 30 '08 #15
"cmdolcet69" <co************@hotmail.comschrieb
Running exactly what you say it always hits my error log and give the
following:
Did you get the same error before inserting my debug code?
Armin
Oct 30 '08 #16
On Oct 30, 12:41*pm, "Armin Zingler" <az.nos...@freenet.dewrote:
"cmdolcet69" <colin_dolce...@hotmail.comschrieb
Running exactly what you say it always hits my error log and give the
following:

Did you get the same error before inserting my debug code?

Armin
no never
Oct 30 '08 #17
On Oct 30, 12:41*pm, "Armin Zingler" <az.nos...@freenet.dewrote:
"cmdolcet69" <colin_dolce...@hotmail.comschrieb
Running exactly what you say it always hits my error log and give the
following:

Did you get the same error before inserting my debug code?

Armin
Sorry it was some code I left in while test....After re adding your
code I had to make a change with the Debug.Print(args(0).ToString)
the args(1) to (0) because it only has 1 position in the
array....however looking at the output window I can;t see where its
writing the comport????
Oct 30 '08 #18
On Oct 30, 12:41*pm, "Armin Zingler" <az.nos...@freenet.dewrote:
"cmdolcet69" <colin_dolce...@hotmail.comschrieb
Running exactly what you say it always hits my error log and give the
following:

Did you get the same error before inserting my debug code?

Armin
Actaully it didn;t print out to my output window however I was able to
see that there is no sequence for the COM1 or COM2 ports being
called.....There could be 5 COM2 in a row or it could alternate COM1
and COM2 there is no pattern what I can see..... So in this
GetDualDSIInputCOM1 Sub how can I read COM1 data and COM 2 data at
the same time????
Oct 30 '08 #19
"cmdolcet69" <co************@hotmail.comschrieb im Newsbeitrag
news:0b**********************************@26g2000h sk.googlegroups.com...
On Oct 30, 12:41 pm, "Armin Zingler" <az.nos...@freenet.dewrote:
"cmdolcet69" <colin_dolce...@hotmail.comschrieb
Running exactly what you say it always hits my error log and give the
following:
Did you get the same error before inserting my debug code?

no never
You had these two lines:

dataBackgroundWorker.RunWorkerAsync(New Object() {currentSerial})
dataBackgroundWorker2.RunWorkerAsync(New Object() {currentSerial2})

I thought it is obvious that I only added two members to the array. You
don't have to add the two lines again because they are already there.

So, again, you just have to _change_ this

dataBackgroundWorker.RunWorkerAsync(New Object() {currentSerial})
dataBackgroundWorker2.RunWorkerAsync(New Object() {currentSerial2})

to this:

dataBackgroundWorker.RunWorkerAsync( _
New Object() {currentSerial,"port 1"} _
)

dataBackgroundWorker2.RunWorkerAsync( _
New Object() {currentSerial2,"port 2"} _
)

Do NOT insert the two lines again, only CHANGE them. Then the error must go
away. Run it without breakpoints and without interruption, and then answer
the question, if only "port 1" is shown in the output/debug window.
Armin

Oct 30 '08 #20

Sorry it was some code I left in while test....After re adding your
code I had to make a change with the Debug.Print(args(0).ToString)
the args(1) to (0) because it only has 1 position in the
array....however looking at the output window I can;t see where its
writing the comport????

=====

No! It must have two items because I did add them here:

.... New Object() {currentSerial,"port 1"})

You see that the array has two items now. They are referred to by args(0)
and args(1) in sub DoDualDSIWorkCOM1.
I wrote "debug/output window". Did you also look in the debug window?
Armin

Oct 30 '08 #21

Actaully it didn;t print out to my output window however I was able to
see that there is no sequence for the COM1 or COM2 ports being
called.....There could be 5 COM2 in a row or it could alternate COM1
and COM2 there is no pattern what I can see..... So in this
GetDualDSIInputCOM1 Sub how can I read COM1 data and COM 2 data at
the same time????

====

I don't find an error. It should work. Before you don't see the debug output
("port 1"/"port 2") I can not help. Did you enable Release
configuration? Switch to Debug configuration. Otherwise Debug.Print is
ignored.
Armin

Oct 30 '08 #22
On Oct 30, 12:59*pm, "Armin Zingler" <az.nos...@freenet.dewrote:
"cmdolcet69" <colin_dolce...@hotmail.comschrieb im Newsbeitragnews:0b******************************** **@26g2000hsk.googlegroups.com...
On Oct 30, 12:41 pm, "Armin Zingler" <az.nos...@freenet.dewrote:
"cmdolcet69" <colin_dolce...@hotmail.comschrieb
Running exactly what you say it always hits my error log and give the
following:
Did you get the same error before inserting my debug code?
no never

You had these two lines:

* * dataBackgroundWorker.RunWorkerAsync(New Object() {currentSerial})
* * dataBackgroundWorker2.RunWorkerAsync(New Object() {currentSerial2})

I thought it is obvious that I only added two members to the array. You
don't have to add the two lines again because they are already there.

So, again, you just have to _change_ this

* * dataBackgroundWorker.RunWorkerAsync(New Object() {currentSerial})
* * dataBackgroundWorker2.RunWorkerAsync(New Object() {currentSerial2})

to this:

* * dataBackgroundWorker.RunWorkerAsync( _
* * * * New Object() {currentSerial,"port 1"} _
* * )

* * dataBackgroundWorker2.RunWorkerAsync( _
* * * * New Object() {currentSerial2,"port 2"} _
* * )

Do NOT insert the two lines again, only CHANGE them. Then the error must go
away. Run it without breakpoints and without interruption, and then answer
the question, if only "port 1" is shown in the output/debug window.

Armin
This was your question: Do you only get "port 1"in the debug/output
window?
My answer: No it will alternate Port1 and Port 2 but some times it
will have 4 or 5 port 2 and only 1 port 1 or 6 port 1 and 1 port 2.

There is no pattern?
Therefore we know that port 1 and port 2 are coming over how can i
read both port simultaneously? to get there values returned?
Oct 30 '08 #23
"cmdolcet69" <co************@hotmail.comschrieb
This was your question: Do you only get "port 1"in the debug/output
window?
My answer: No it will alternate Port1 and Port 2 but some times it
will have 4 or 5 port 2 and only 1 port 1 or 6 port 1 and 1 port 2.

There is no pattern?
Therefore we know that port 1 and port 2 are coming over how can i
read both port simultaneously? to get there values returned?

Aaah, I start seeing what you mean with "simultaneously".

Well,,,,, yes, there is no pattern. Even if you have a dual core or multi
core CPU, you can _not_ assume that two tasks running on two cores will do
exactly the same at the same time forever. This is because of..._many_
reasons. I'm not gonny elaborate on this here. The OS might interrupt the
threads at different times or whatever. They are not even started at the
same time. And so on. And what even would you expect on a single core CPU?
So, no, there is no 100% guaranteed execution of the same code in two
threads at the same time. The probability even converges to zero.
Obviously you are trying to _synchronize_ two threads or two tasks. This
must be done on a higher level. You must implement a synchronization
mechanism. How this is done depends on what you are trying to achieve.

So, the debug output has shown that both ports are being processed. Period.
Now we can go a step further: _What_ do you have to synchronize? Which
actual problem are you being faced?
Armin

Oct 30 '08 #24
On Oct 30, 2:06*pm, "Armin Zingler" <az.nos...@freenet.dewrote:
"cmdolcet69" <colin_dolce...@hotmail.comschrieb
This was your question: Do you only get "port 1"in the debug/output
window?
My answer: No it will alternate Port1 and Port 2 but some times it
will have 4 or 5 port 2 and only 1 port 1 or 6 port 1 and 1 port 2.
There is no pattern?
Therefore we know that port 1 and port 2 are coming over how can i
read both port simultaneously? to get there values returned?

Aaah, I start seeing what you mean with "simultaneously".

Well,,,,, yes, there is no pattern. Even if you have a dual core or multi
core CPU, you can _not_ assume that two tasks running on two cores will do
exactly the same at the same time forever. This is because of..._many_
reasons. I'm not gonny elaborate on this here. The OS might interrupt the
threads at different times or whatever. They are not even started at the
same time. And so on. And what even would you expect on a single core CPU?
So, no, there is no 100% guaranteed execution of the same code in two
threads at the same time. The probability even converges to zero.

Obviously you are trying to _synchronize_ two threads or two tasks. This
must be done on a higher level. You must implement a synchronization
mechanism. How this is done depends on what you are trying to achieve.

So, the debug output has shown that both ports are being processed. Period.
Now we can go a step further: _What_ do you have to synchronize? Which
actual problem are you being faced?

Armin
I need to take readings from two separate IO devices in this case one
device sends two readings over and the other device sends only one
reading over.....What i need to achieve is that both devices need to
populate there own unique textboxes in the runtime screen. I have
written the code for the unique textboxes however i just can't read
both com ports at the same time.
Oct 30 '08 #25
This is still not crystal clear.

Define the "same time" ? What is the problem with filling the unique textbox
for COM1 when you receive data from COM1 and the unique textbox for COM2
when you receive data from COM2 ? At any one time you'll just see whatever
was sent last by the particular COM port for this textbox

Yes you'll have possibly a slight discrepencies but does it really matter ?
Moreover it would be surprising to have those two devices sending their data
to your PC at the exact same time so anyway you'll do have a slight
difference...

If you expect to have the exact same number of data transmitted by those two
COM ports (?!) you could just count the data input so that you know that you
receive the 11th data from COM1, then the 12 th data from COM1 and then the
11th data from COM2 and you'll be able to retrieve the matching data you
just got from COM1.

--
Patrice
I need to take readings from two separate IO devices in this case one
device sends two readings over and the other device sends only one
reading over.....What i need to achieve is that both devices need to
populate there own unique textboxes in the runtime screen. I have
written the code for the unique textboxes however i just can't read
both com ports at the same time.

Oct 30 '08 #26
I need to take readings from two separate IO devices in this case one
device sends two readings over and the other device sends only one
reading over.....What i need to achieve is that both devices need to
populate there own unique textboxes in the runtime screen. I have
written the code for the unique textboxes however i just can't read
both com ports at the same time.

=====

No, you can read them at the "same" time. Please tell us the _actual_
problem! You fill one textbox from one port and the other textbox from the
other port. If this works, where is the problem?
Again, I can only guess what you mean:
You want to create a relationship between the data from port 1 and the data
from port 2. To achieve this, you wanted to receive data "simultaneously".
Is this right? This would be a kind of turn-based game that you wanted to
play. To do this, you have to complete one round by waiting for both ports
having finished receiving data. Then you can take the two packages from the
two ports and build a relationship. Then start the next round.

I assume that the data itself does not contain any information that can help
you creating a relationship later. What I can say for sure is that the
date/time is _not_ the unique key to create the relationship.
Armin

Oct 30 '08 #27


Maybe It's just me, but looking at your original question, in relation to
the background worker, is can you send more than one argument back and forth
to the background worker class.

If that is the question, the answer is yes, and you won't need multiple
background workers to do what you're trying to accomplish.

There are several ways to do this; my preferred method is to create an
object dedicated to the task, and pass that to and from the background
worker.

You can likewise create a class or struct to report back more than one
element of progress.

Another (worse) ideas; throw the values you want to pass into a hashtable or
other collection and pass that through as an argument into the
BackgroundWorker

Regards,

-Mark
"cmdolcet69" <co************@hotmail.comwrote in message
news:85**********************************@d45g2000 hsc.googlegroups.com...
Can anyone tell me if its possible to do multiple event args in vb.net?
Oct 30 '08 #28

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: alex | last post by:
Hi, it is possible to define multiple initialization methods so that the method is used that fits? I am thinking of something like this: def __init__(self, par1, par2): self.init(par1,...
5
by: fooooo | last post by:
This is a network app, written in wxPython and the socket module. This is what I want to happen: GUI app starts. User clicks a button to 'start' the work of the app. When start is pressed, a new...
4
by: NutJob | last post by:
Hello, I'm faced with the following problem: I have a (secondary) thread that monitors a socket for incoming message traffic using the select.select() function. Besides that I also have the...
13
by: DraguVaso | last post by:
Hi, I have a Generic List, for instance: Public MyPersonnesDeContact As New System.Collections.Generic.List(Of clsPersonne) My clsPersonne raises some events, and I want to be able to handle...
3
by: | last post by:
Hello, I am trying to get add a product to a cart from a gridview control when a button in the gridview is clicked. I have a book on how to do this in asp.net 2.0 but it is done by specifying...
4
by: John Veldthuis | last post by:
I have set up a background worker and now find I need to give it multiple arguments. What is the best way of doing this? An example would be nice.
6
by: Peter M. | last post by:
Hi all, If an event has multiple subscribers, is it possible to cancel the invocation of event handlers from an event handler? Or to be more specific: I'm subscribing to the ColumnChanging...
0
by: =?Utf-8?B?YW5rMmdv?= | last post by:
Hi, Thanks in advance for reading this. Not sure where to post this question, but I hope someone in here can help. Trying to write to Event Log in VS 2005 (.NET 2.0) using Enterprise Library...
1
by: cmdolcet69 | last post by:
So I have two handlers: AddHandler dataBackgroundWorker.DoWork, AddressOf DoDualDSIWorkCOM1 AddHandler dataBackgroundWorker2.DoWork, AddressOf DoDualDSIWorkCOM1 ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.