Multiple event Args in VB 2005

  • Thread starter Thread starter cmdolcet69
  • Start date Start date
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
 
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?
 
cmdolcet69 said:
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
 
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.
 
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
 
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
 
Back
Top