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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:04:38+00:00 2026-05-13T23:04:38+00:00

I’m writing an application that displays a list of objects which the user can

  • 0

I’m writing an application that displays a list of objects which the user can select and then view and edit the properties of through a PropertyGrid control. The object’s properties are populated by time consuming process of extracting information from files through the use of a secondary thread. But I’d also like to allow the user to continue viewing other objects as the extraction process is proceeding.

After reading the responses to my previous questions on SO. It sounds like because the properties that are being written by the extraction process do not intersect the properties that are editable by the user through the property grid I shouldn’t have an issue with the two threads editing the objects at the same time. Although it’s possible for the user to see an incorrect value if they are incredibly unlucky and the property grid end up reading the object in the middle of a non-atomic write.

However, I’d still like to know how I might set this up to prevent the user from editing or viewing an object which is in the middle of being extracted. I’m very very new to multithreading, but most examples that I’ve read so for show a separate token Object being created to use to lock access to to the actual Object of interest. The answers to my other previous question confirmed that it is typical to create a separate object like this specifically for locking.

So now what I’d like to know is how is this handled in my case where I have a large collection of objects? I’d like to create locks that prevents the property grid from displaying the object a user selects if it is currently being extracted to.

Do I need to create a separate collection of lock Objects that is kept in sync with my real collection? So if an object is added or removed from my main collection I have to add or remove lock objects from my lock collection?

Do I lock to the actual objects rather then creating separate token lock objects?

What about adding a “IsBeingExtracted” Boolean property to the objects that the property grid can check to see if the object is in the middle of being written to? This would then be set at the very beginning and very end of the extraction process.

Or how about a static field somewhere that references the current (if any) object that is current being extracted to. The property grid could then check that the latest object it was ask to display was not the object referenced by this static field? This of course wouldn’t work if there were multiple extraction threads.

What’s the best/correct way to do this? Personally I like the boolean property option the best, but would like to know what others who actually know what they are doing think.

  • 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-13T23:04:38+00:00Added an answer on May 13, 2026 at 11:04 pm

    Couldn’t you just make the collection that holds the objects a SynchronizedCollection<T>? It will make sure that only one thread can add or access objects at a time. Then, rather than worry about how to synchronize access to each object’s properties, don’t add the object to the collection until it has been populated.

    Something like this:

    private readonly ICollection<Item> Items = new SynchronizedCollection<Item>();
    
    // Run this on the background thread.
    public void PopulateItems()
    {
        using (var file = File.OpenRead("BigFile.txt"))
        using (var reader = new StreamReader(file))
        {
            while (!reader.EndOfStream)
            {
                var item = new Item();
                PopulateItem(item);
                Items.Add(item);
            }
        }
    }
    
    public void PopulateItem(Item item)
    {
        // Do time-consuming work.
    }
    

    The property grid can happily do whatever it wants with the object because by the time it shows up in the list, the extraction thread is finished with it. No explicit locking required.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

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.