-3

Multi-Threaded application , using static dictionary . which will be used to process the request , each request will access only one record .

Processing the Request

  1. Read Record
  2. Algorithm to calculate the values
  3. Update the record.

During the process that particular record needs to blocked .

static Dictionary<string, InstacneLevel> objlevel; -- Static variable

lock (key)
{
  // need to lock required key 
  // read , Calclulate and update the value for that key
}

I dont find any Clue , can anyone please help me out.

Can i go with ConcurrentDictionary??

Parthi
  • 69
  • 1
  • 2
  • 12
  • i dont want to lock entire dictionary , just want to lock one record , because other thread can process with other records .. – Parthi Jul 10 '14 at 13:09

1 Answers1

0

The easy answser is "yes, use concurrentdictionary", but before you do, take care to read this article which explains its deficiencies and performance penalties.

http://www.codeproject.com/Articles/548406/Dictionary-plus-Locking-versus-ConcurrentDictionar

PhillipH
  • 6,182
  • 1
  • 15
  • 25
  • I think , when i update the value in concurrent dictionary it internally lock d record and thread safe . But i don't find option to lock the record to particular code block to be execute. – Parthi Jul 10 '14 at 13:17
  • Ok, I understand. In which case if the Key is a string object then writing a wrapper class and hiding the instance of the dictionary inside it as a private, then implementing your own IDictionary interface on your wrapper class (with appropriate exclusive locks using the string Key value as required by your business logic) is the way to go. – PhillipH Jul 11 '14 at 09:16
  • Ok, I Got it . Do you have any reference article for this implementation ? if so it would be definitely helpful . Thanks – Parthi Jul 11 '14 at 12:32