Answer by Robert Fraser for "A reference to a volatile field will not be...
Use this:#pragma warning disable 420if(Interlocked.CompareExchange(ref isLoaded, 1, 0) != 0) return;#pragma warning restore 420
View ArticleAnswer by Darin Dimitrov for "A reference to a volatile field will not be...
You are not doing anything wrong. According to the documentation:A volatile field should not normally be passed using a ref or out parameter, since it will not be treated as volatile within the scope...
View ArticleAnswer by Jon Skeet for "A reference to a volatile field will not be treated...
Basically the warning is that when you pass a volatile field by reference, the calling code doesn't know to treat it in a volatile manner. For Interlocked.Increment that probably doesn't matter, due to...
View ArticleAnswer by Kent Boogaart for "A reference to a volatile field will not be...
You're getting the error because you're passing the field by reference. I think what this means is that the target method has no idea the field is marked as volatile, and therefore will not treat it as...
View Article"A reference to a volatile field will not be treated as volatile" implications
The following codeusing System.Threading;class Test{ volatile int counter = 0; public void Increment() { Interlocked.Increment(ref counter); }}Raises the following compiler warning:"A reference to a...
View Article