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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:46:49+00:00 2026-05-14T03:46:49+00:00

I have implemented ReaderWriterLockSlim, Now i don’t want it to wait at the lock.

  • 0

I have implemented ReaderWriterLockSlim, Now i don’t want it to wait at the lock. I want to do something else if the lock is held.

I considered using is isWriterLockHeld but it does not makes much sense to me, Since if two threads come in at the same time and enter the if statement at the same time one will still be waiting at the lock

here is my code.

ReaderWriterLockSlim rw = GetLoadingLock(parameters);
rw = GetLoadingLock(parameters);
try
{
  rw.EnterWriteLock();
  item = this.retrieveCacheItem(parameters.ToString(), false);
  if (item != null)
  {
      parameters.DataCameFromCache = true;

      // if the data was found in the cache, return it immediately
      return item.data;                              
  }
  else
  {
      try
      {
          object loaditem = null;
          itemsLoading[parameters.ToString()] = true;
          loaditem = this.retrieveDataFromStore(parameters);
          return loaditem;
      }
      finally {
         itemsLoading.Remove(parameters.ToString());
      }
  }
}
finally
{
  rw.ExitWriteLock();
}

Can anyone please guide me in the right direction with this.

Thanks

  • 1 1 Answer
  • 2 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-14T03:46:49+00:00Added an answer on May 14, 2026 at 3:46 am

    You can use the overload of TryEnterWriteLock() that takes a timeout as a parameter. If you pass it zero, it returns immediately if the lock could not be taken.

    if(rw.TryEnterWriteLock(0))
    {
        // do something with the lock held (don't forget to use a try/finally)
    }
    else
    {
        // do something if the lock fails
    }
    

    On another matter, why are you assigning rw twice?

    ReaderWriterLockSlim rw = GetLoadingLock(parameters);
    rw = GetLoadingLock(parameters); // This line is probably redundant
    

    If you’re using a Dictionary<string,bool> for itemsLoading, you can use an HashSet<string> instead.

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

Sidebar

Related Questions

I have implemented my GWT application using Spring + GWTP. I want to access
I have implemented audio playback using AVPlayer, playing a remote mp3 url. I want
I have implemented background worker class something similar to below sample and I want
I have implemented arbitrary links in my rtb using the CodeProject found here .
I have implemented changing the brightness of an image using uislider in iPhone without
I have implemented a simple linked list class and I would now like to
I have implemented vibration using vibrator .In my application, when the user press the
I have implemented the touch functionality to my website using these code and it
I have implemented the ViewPagerIndicator with ActionBarSherlock. Now i would like to open a
I have implemented a view-based NSOutlineView in my project. I am using floating group

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.