Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8599145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:19:42+00:00 2026-06-12T01:19:42+00:00

I have an array list which is continuously updated every second. I have to

  • 0

I have an array list which is continuously updated every second. I have to use the same array list in two other threads and make local copies of it. I have done all of this but i get weird exceptions of index out of bound , What i have found out so far is that i have to ensure some synchronization mechanism for the array list to be used across multiple threads.

this is how i am making it synchronized:

for (int i = 0; i < Globls.iterationCount; i++)
            {
                if (bw_Obj.CancellationPending)
                {
                    eve.Cancel = true;
                    break;
                }

                byte[] rawData4 = DMM4.IO.Read(4 * numReadings);
                TempDisplayData_DMM4.Add(rawData4);
                Globls.Display_DataDMM4 = ArrayList.Synchronized(TempDisplayData_DMM4);
                Globls.Write_DataDMM4 = ArrayList.Synchronized(TempDisplayData_DMM4);

            }

in other thread i do the following to make local copies:

ArrayList Local_Write_DMM4 = new ArrayList();
Local_Write_DMM4 = new ArrayList(Globls.Write_DataDMM4); 

Am i synchronizing the arraylist in right way?, also do i need to lock while copying array-list as well:

 lock (Globls.Display_DataDMM4.SyncRoot){Local_Temp_Display1 = new ArrayList(Globls.Display_DataDMM4);}

or for single operations its safe?. I haven’t actually ran this code i need to run it over the weekend and i don’t want to see another exception :(. please help me on this!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T01:19:44+00:00Added an answer on June 12, 2026 at 1:19 am

    as @Trickery stated assignment needs to be locked since the source array Globls.Write_DataDMM4 can be modified by another thread during enumeration.
    It is essential therefore to lock both when populating the original array and when making your copy

    for (int i = 0; i < Globls.iterationCount; i++)
    {
        if (bw_Obj.CancellationPending)
        {
            eve.Cancel = true;
            break;
        }
    
        byte[] rawData4 = DMM4.IO.Read(4 * numReadings);
        TempDisplayData_DMM4.Add(rawData4);
    
        lock (Globls.Display_DataDMM4.SyncRoot)
        {
        Globls.Write_DataDMM4 = ArrayList.Synchronized(TempDisplayData_DMM4);
        }
    
    }
    

    and

    lock (Globls.Display_DataDMM4.SyncRoot)
    {
         Local_Temp_Display1 = new ArrayList(Globls.Display_DataDMM4);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Array list of a custom class which is essentially has two
I have an array list named newSymptomList which contains a list of Symptom id's
I have a collection (or list or array list) in which I want to
I have an array list which is connected with a private static function and
I have a huge array list which contains 1000 entries out of which one
Say you need to have a list/array of integers which you need iterate frequently,
I have a Array list which contains Objects of Restaurants ArrayList<Restaurants> array_sort = new
I have a array list which have a list of a type, but all
I have an array List<SomeObject> which contain ascending order of dates (and some more
I have a byte list variable which I store byte array information here: internal

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.