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

  • Home
  • SEARCH
  • 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 8908611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:13:31+00:00 2026-06-15T03:13:31+00:00

I have the following code: var sequence = from row in CicApplication.DistributorBackpressure44Cache where row.Coater

  • 0

I have the following code:

    var sequence = from row in CicApplication.DistributorBackpressure44Cache
                   where row.Coater == this.Coater && row.IsDistributorInUse
                   select new GenericValue
                   {
                       ReadTime = row.CoaterTime.Value,
                       Value = row.BackpressureLeft
                   };

    this.EvaluateBackpressure(sequence, "BackpressureLeftTarget");

And DistributorBackpressure44Cache is defined as follows:

internal static List<DistributorBackpressure44> DistributorBackpressure44Cache
{
    get
    {
        return _distributorBackpressure44;
    }
}

This is part of a heavily threaded application where DistributorBackpressure44Cache could be being refreshed in one thread, and queried from, as shown above, in another thread. The variable ‘sequence’ above is an IEnumerable, which is passed to the method shown, and then potentially passed to the other methods, before actually being executed. My concern is this. What will happen with the above query if the DistributorBackpressure44Cache is being refreshed (cleared and repopulated) when the query is actually executed?

It wouldn’t do any good to put a lock around this code because this query actually gets executed at some point later (unless I were to convert it to a list immediately).

  • 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-15T03:13:32+00:00Added an answer on June 15, 2026 at 3:13 am

    If your design can tolerate it, you could ensure snapshot level isolation with this code and avoid locking altogether. However, you would need to do the following:

    1. Make DistributorBackpressure44Cache return a ReadOnlyCollection<T> instead, this way it is explicit you shouldn’t mutate this data.

    2. Ensure that any mutations to _distributorBackpressure44 occur on a copy and result in an atomic assignment back to _distributorBackpressure44 when complete.

      var cache = _distributorBackpressure44.ToList();
      this.RefreshCache(cache); // this assumes you *need* to know 
                                // about the structure of the old list
                                // a design where this is not required
                                // is preferred
      
      _distributorBackpressure44 = cache; // some readers will have "old"
                                          // views of the cache, but all readers
                                          // from some time T (where T < Twrite)
                                          // will use the same "snapshot"
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: var personIds = from player in myPlayers select player.person_id;
I have the following code: var carsContext = new CarsDataContext(); IQueryable<Car> allCars = carsContext.Cars;
I have the following code: var tlp = new TableLayoutPanel { Location = new
I have the following code: var from = 0, step = 5; function showNext(list)
I have the following code: var numberOfSelectedOptions = new Array(); numberOfSelectedOptions[0]=0; numberOfSelectedOptions[1]=0; numberOfSelectedOptions[2]=0; $(a.tagvariantoption).live(click,
I have the following code: var words = new Object(); $(li.words).each(function(){ var thisId =
I have the following code: var currentUser = (from i in _dbContext.Users where i.FirstName
I have the following code var query = from lookup in dataset.Tables[MBDDX_LOOKUP].AsEnumerable() where lookup.Field<string>(lookup_value)
Not sure I can explain this properly.... I have the following sequence of code
Inside my viewmodel I have following code: var self = this; self.Name = ko.observable(data.Name);

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.