1

I'm trying to find the best solution (performance & accurate) to have a static list of objects in a web service.

Some web methods will be making amendments to these objects and returning the state of the object after the amendments and others will be requesting the current state.

This needs to be accurate at every operation as it's money related. This web service will be bombarded with requests from different areas of our large scale project.

I've been looking at ConcurrentDictionary, and while reading some other SO questions I came across the following answer: https://stackoverflow.com/a/1966462/151625

The following paragraph is something that I do not want:

Now consider this. In the store with one clerk, what if you get all the way to the front of the line, and ask the clerk "Do you have any toilet paper", and he says "Yes", and then you go "Ok, I'll get back to you when I know how much I need", then by the time you're back at the front of the line, the store can of course be sold out. This scenario is not prevented by a threadsafe collection.

So essentially I'm asking, should I lock values within a ConcurrentDictionary, or does it defeat the whole purpose of it? If I should/could, what is the best way to do it, if not, what alternative do I have?

Community
  • 1
  • 1
Matthew Grima
  • 1,513
  • 5
  • 25
  • 40

0 Answers0