C
cmdolcet69
Can anyone tell me if its possible to do multiple event args in vb.net?
cmdolcet69 said:Can anyone tell me if its possible to do multiple event args in
vb.net?
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 said:Can anyone tell me if its possible to do multiple event args in vb.net?
cmdolcet69 said: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
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
cmdolcet69 said: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)
[...]
COM1Active = 1
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
cmdolcet69 said: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!!!!
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
ArminI 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 timeCan 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
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
ArminI 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 timeCan 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
cmdolcet69 said:Running exactly what you say it always hits my error log and give the
following:
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
ArminI 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 timeCan 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
Did you get the same error before inserting my debug code?
Armin
Did you get the same error before inserting my debug code?
Armin
no never
Did you get the same error before inserting my debug code?
Armin