I store this class
public class Customer
{
public string Firstname { get; set; }
public string Lastname { get; set; }
public string CustID { get; set; }
}
In this dictionary :
public static ConcurrentDictonary<string, Customer> Customers = new ConcurrentDictonary<string, Customer>();
The key is a unique string for each customer.
I am trying to find the cleanest thread-safe way to update properties of the customer's stored in the dictionary.
Sorry if the code above has any syntax issues, typed it in from a smartphone.
Here is what I’m currently doing:
Customer oCustomers = new Customer();
Customers.tryGetValue(ID, out oCustomers);
Customer nCustomer = new Customer();
nCustomer = oCustomer;
nCustomer.Firstname = NewValue;
Customers.tryUpdate(ID, nCustomer, oCustomer);
This works but seems so hacked to me, any suggestions would be great.
This was closed as a duplicated question that asks how to modify the ConcurrentDictionary in a thred-safe way. I'm asking how to modify individual customers, not the dictionary.
I have not found an answer on stack overflow and have searched for some time. Will someone please re-open this question so I can’t get the help I came here for.