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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:55:26+00:00 2026-06-13T09:55:26+00:00

My application stores two related bits of data in application state. Each time I

  • 0

My application stores two related bits of data in application state. Each time I read these two values, I may (depending on their values) need to update both of them.

So to prevent updating them while another thread is in the middle of reading them, I’m locking application state.

But the documentation for HttpApplicationState.Lock Method really doesn’t tell me exactly what it does.

For example:

  1. How does it lock? Does it block any other thread from writing the data?

  2. Does it also block read access? If not, then this exercise is pointless because the two values could be updated after another thread has read the first value but before it has read the second.

In addition to preventing multiple threads from writing the data at the same time, it is helpful to also prevent a thread from reading while another thread is writing; otherwise, the first thread could think it needs to refresh the data when it’s not necessary. I want to limit the number of times I perform the refresh.

  • 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-13T09:55:27+00:00Added an answer on June 13, 2026 at 9:55 am

    Looking at the code is locking only the write, not the read.

    public void Lock()
    {
        this._lock.AcquireWrite();
    }
    public void UnLock()
    {
        this._lock.ReleaseWrite();
    }
    public object this[string name]
    {
        get
        {
            return this.Get(name);
        }
        set
        {
            // here is the effect on the lock
            this.Set(name, value);
        }
    }
    public void Set(string name, object value)
    {
        this._lock.AcquireWrite();
        try
        {
            base.BaseSet(name, value);
        }
        finally
        {
            this._lock.ReleaseWrite();
        }
    }
    
    public object Get(string name)
    {
        object obj2 = null;
        this._lock.AcquireRead();
        try
        {
            obj2 = base.BaseGet(name);
        }
        finally
        {
            this._lock.ReleaseRead();
        }
        return obj2;
    }
    

    The write and the read is thread safe, meaning have all ready the lock mechanism. So if you going on a loop that you read data, you can lock it outside to prevent other break the list.

    Its also good to read this answer: Using static variables instead of Application state in ASP.NET

    Its better to avoid use the Application to store data, and direct use a static member with your lock mechanism, because first of all MS suggest it, and second because the read/write to application static data is call the locking on every access of the data.

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

Sidebar

Related Questions

My web application stores URL segments in a database. These URL segments are based
Our application currently stores bunch of configuraton & application specific data to files on
I have an application that stores images as NSData in Core Data. I load
I have an application which stores data to the persistent store by setting the
Assume I have a application that stores data,gets data and processes data and stores
I'm developing an application that stores images and related metadata. I'm running into issues
I have a java application that stores some GPS data in a strange format:
We have two distinct agile teams, each working on separate, but related, applications. Each
I have two tables in my application. The first one, Sections, stores content for
Suppose you have an application that consists of two layers: A: A data layer

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.