Basically the warning is that when you pass the volatile field by reference, the calling code does not know to handle it in a volatile way. For Interlocked.Increment, which probably doesn't matter due to the nature of the method - but then you don't need a variable to be mutable anyway if you use Interlocked.
In general, I think that I would not mix the two - if you use Interlocked, do it everywhere (using Interlocked.CompareExchange(ref counter, 0, 0) to read it). I can’t say that I often use volatility, personally. For simple counters, I can use Interlocked, but I most likely use locking for most tasks.
Jon Skeet Jan 08 '09 at 17:28 2009-01-08 17:28
source share