i am working in an advanced multi threaded application, in which i need to change some variable values atomically. what i did so far is this:
private object _lock = new object();
public void ChangeValueAtomically(int a, int b, int comparingValue)
{
if (a == comparingValue)
{
lock (_lock)
{
if (a == comparingValue)
{
a = b;
}
}
}
}
But it’s causing my code to be so slow, as i need to do so many value changing atomically on a long list of listbox items in WPF.
is there any faster way to change variable values atomically, taking in consideration the value comparison?