class CFoo
{
private string _filePathFormatString;
public string Foo()
{
System.Threading.Thread.VolatileRead(ref _filePathFormatString);
...
}
}
string is object, why this VolatileRead doesn’t compile?
I think it should match VolatileRead(ref object) signature.
Types of formal and actual parameters must be exactly the same if you pass parameter with “ref” in C#. So you can change field to be type of object. Second way to do it might be using ReaderWriteLockSlim instead of volatile read.