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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:07:08+00:00 2026-05-16T15:07:08+00:00

Consider the following situation: I’m using the Application object in ASP.NET to store a

  • 0

Consider the following situation: I’m using the Application object in ASP.NET to store a collection(List(of MyObject)) that is being accessed concurrently by several users. While I understand that reading from the Application object is thread safe, I’m wonder how I should make this code thread safe:

objList = Application("GlobalList")

objList.add(AnotherValue)

application("GlobalList") = objList

or

objList = Application("GlobalList")

dim PrunedList as MyObject() = (from o as MyObject in objList where o.SomeProperty = SomeValue).ToArray()

objList.Clear()

For each PrunedListObject as MyObject in PrunedList
   objList.add(PrunedListObject)
next

application("GlobalList") = objList

I read a little about Application.Lock() which basically is a mutex but I worry about the performance impact blocking other threads while manipulating Application("GlobalList") Is Application.Lock() the correct approach?

  • 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-16T15:07:09+00:00Added an answer on May 16, 2026 at 3:07 pm

    I’m not an expert in ASP.NET specifically, but I did use it for a few years. Pretty much the Application storage is there for some sense of backwards compatibility with classic ASP. You would need try/finally blocks to lock and unlock and it’s still not nearly as flexible as using some of the other locking mechanisms in .NET that were not there in classic ASP.

    In your example, Lock/Unlock would need to be very broad because even after you’ve grabbed “GlobalList” multiple threads writing to this collection at the same time will still cause concurrency problems.

    But in general, any multi-threaded read/write access to a collection is inherently unsafe. You would have the same problem with any collection. But using static fields, you could have multiple threads accessing individual values in a strongly typed fashion with no “magic strings” as is required by a dictionary. Also you wouldn’t need to lock in many cases.

    You could do something like this without using the Application storage at all. Note that you still need to synchronize access to the collection but you don’t need to lock/unlock the entire application state dictionary.

    Private Shared GlobalList As New List(Of Foo)()
    
    ...
    
    SyncLock GlobalList
        // Only one thread can proceed here at a time
    End SyncLock
    

    If performance does become impacted due to multiple readers blocking each other even if no writes are going on, you can switch to using a reader-writer lock. There is an implementation of this in .NET called ReaderWriterLockSlim that allows multiple readers to execute concurrently as long as there are no writers holding the lock. This gives you significantly better performance when there are more readers than writers. Using this kind of lock is a bit trickier though because there is no syntactic sugar like C#’s lock statement or VB’s SyncLock.

    EDIT

    As noted in the comments below, you should always consider the performance implications of whatever locking strategy you use. In particular, ReaderWriterLockSlim may actually degrade performance if there is not a lot of contention between readers. Here’s a post on MSDN comparing Monitor and ReaderWriterLockSlim. http://blogs.msdn.com/b/pedram/archive/2007/10/07/a-performance-comparison-of-readerwriterlockslim-with-readerwriterlock.aspx

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

Sidebar

Related Questions

Consider the following situation: WidgetCompany produced a .NET DLL in 2006 called Widget.dll, version
please consider the following scenario for .net 2.0: I have an event that is
Consider the following situation where I have a list of n matrices (this is
Consider the following situation. -(void) foo { Object * obj = [[Object alloc] init];
Consider the following code: void Handler(object o, EventArgs e) { // I swear o
Consider the following situation file: ./include/functions/table-config.php containing: . . $tablePages = 'orweb_pages'; . .
Consider the following situation class URISplit { var $REQ_URI; //some more variables function __construct($uri)
Consider the following situation: - Suppose my app allows users to create the states
Consider the following situation: There is a serialization file, created by the older version
Consider the following situation Code was added to the trunk at revision x 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.