[Last Call] Learn how to a build a cloud-first strategyRegister Now


Insert into database from arraylist

Posted on 2011-05-07
Medium Priority
Last Modified: 2012-06-22
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
    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
        ElseIf Hilo_inserta_pila.ThreadState = ThreadState.Stopped Then
            Dim Hilo_inserta_pila As New Thread(AddressOf lee_e_inserta_pila)
        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"))

    End Sub

Open in new window


Thank you very much.
Question by:Yawes
1 Comment
LVL 83

Accepted Solution

CodeCruiser earned 2000 total points
ID: 35716147
You can use a structure such as a Queue where one process is adding values and another thread is dequeuing values and saving to DB.

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month17 days, 18 hours left to enroll

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question