Link to home
Start Free TrialLog in
Avatar of Yawes
Yawes

asked on

Insert into database from arraylist

Hi all I have a problem I can not solve.

On many occasions I need to insert into database records that
taking place in real time and at great speed and always
encounter with the problem that information is lost. I had thought
use an arraylist to insert the data and another thread turned
every x seconds to cross it and write to the db, but I can not put
running because I have errors like "Collection was modified; can
not to execute the operation of that list.. Surely there is a
way to go.

Extensive information:

I'm working on reading a value using a socket, which changes each
100 ms and I have to store it in database each and every one of
them, and my idea was first stored in an arraylist, I checked
not lose any records. Now the problem is to pass
bd, without the process stops, ie the reading continues
I can not wait for a pause to store as the process can
take hours to stop.
Right now I have this code simplified test.
Dim pila_1 As New ArrayList
  Dim Hilo_inserta_pila As New Thread(AddressOf lee_e_inserta_pila) 


'.....

    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
         pila_1.Add(Valor_leido)
    End Sub


    Private Sub Timer2_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        If (Hilo_inserta_pila.ThreadState And ThreadState.Unstarted) <> 0 Then
            Hilo_inserta_pila.Start()
        ElseIf Hilo_inserta_pila.ThreadState = ThreadState.Stopped Then
            Dim Hilo_inserta_pila As New Thread(AddressOf lee_e_inserta_pila)
             Hilo_inserta_pila.Start()
        End If
    End Sub


    Private Sub lee_e_inserta_pila()

        Dim obj As Object
        Dim pila_temp As New ArrayList
        pila_temp = pila_1

        For Each obj In pila_temp
            Table_Adapter.Insert_in_BD(obj, Format(Now, "yyyy/MM/dd"), Format(Now, "HH:mm:ss"))
        Next
        pila_temp.Clear()

    End Sub

Open in new window



VB.NET
MySQL

Thank you very much.
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial