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 3991176
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:35:02+00:00 2026-05-20T06:35:02+00:00

I have four level data structure defined like this: Dictionary<Type1, Dictionary<Type2, Dictionary<Type3, List<Type4>>>> The

  • 0

I have four level data structure defined like this:

Dictionary<Type1, Dictionary<Type2, Dictionary<Type3, List<Type4>>>>

The whole thing is encapsulated in a class which also maintains thread-safety. Currently it just locks whole collection while it reads/manipulates the data (reading is by orders of magnitude more common than writing).

I was thinking of replacing the Dictionary with ConcurrentDictionary and List with ConcurrentBag (its items don’t have to be ordered).

If I do so, can I just eliminate the locks and be sure the concurrent collections will do their job correctly?

  • 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-05-20T06:35:02+00:00Added an answer on May 20, 2026 at 6:35 am

    The concurrent collections will prevent data corruption and crashes, but the code won’t be semantically equivalent to your current one. For example, if you iterate one of the concurrent dictionaries, some of the items may belong to different updates:

    The enumerator returned from the
    dictionary is safe to use concurrently
    with reads and writes to the
    dictionary, however it does not
    represent a moment-in-time snapshot of
    the dictionary. The contents exposed
    through the enumerator may contain
    modifications made to the dictionary
    after GetEnumerator was called.

    If you want to maintain the exact behavior you have now, yet save on the cost of locking, you may want to lock with ReaderWriterLockSlim which is especially suited for cases with more reads than writes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database that has four columns like this level_1, level_2, level_3, level_4
I have a tree data structure with N first-level child nodes that have childs
I have four arrays of data (3072 bytes each.) I want to point to
I have a report in SSRS 2008 that shows data aggregated from four levels
I have a data gathering app (terrestrial magnetic field strength) that has four phases;
There are four high level APIs to access Cassandra and I do not have
I have four tables containing exactly the same columns, and want to create a
I have four flags Current = 0x1 Past = 0x2 Future = 0x4 All
I have four classes which share some arrangement of four properties. I have currently
I have four different lists. headers , descriptions , short_descriptions and misc . I

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.