public bool CompareAndSet(bool expected, bool newValue) { var expectedInt = expected ? _trueValue : _falseValue; var newInt = newValue ? _trueValue : _falseValue; return Interlocked.CompareExchange(ref _value, newInt, expectedInt) == expectedInt; }