We help IT Professionals succeed at work.

Do I Have To Multithread ?

aseker
aseker asked
on
hi everybody

think about that there is one PC and 8 or 9 barcode scanners that are connected to that PC by com ports..i have to do some modifications on a table in my DB by the actions on com ports...

can i handle this by the way below or do i have to multithread ? if yes (multithread) how many threads do i have to design. for each port or a thread ? or for all ports a thread and a thread for other issues

    Private Sub port1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles Port.DataReceived
...
   DB modifications
...
    End Sub

    Private Sub port2_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles Port2.DataReceived
...
   DB modifications
...
    End Sub

.......
......
......

    Private Sub port9_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles Port9.DataReceived
...
   DB modifications
...
    End Sub
Comment
Watch Question

Commented:
Normaly you wont need to use multiple threads.
If i am correct, you connection to database creates something called like a pool.
This will manage your calls to and updates to the database

Greetz!

Author

Commented:
actually i dont worry about the DB side i worry about the data receive side. i mean if 2 or more com ports receives data at the same time, does this case brake my code?
Commented:
Wel from the snippet code that i see, i dont believe it can break your code. And also dont think i wil harm the values.

if you want to implement it with multithreading, the risk of getting bad data is bigger if the multithreading isn't implemented correct (wich aint a simple thing).

Greetz!

Author

Commented:
im not fully satisfied