private bool CompareAndExchangeState(SystemSessionState expectedState, SystemSessionState newState) { var eSi = (int)expectedState; var nSi = (int)newState; var result = Interlocked.CompareExchange( ref _currentState, nSi, eSi) == eSi; if (result) { log.Trace($"State change from {expectedState} to {newState}."); } return(result); }
private void SetState(SystemSessionState newState) { log.Trace($"Change the state to {newState}."); Interlocked.MemoryBarrier(); Volatile.Write(ref _currentState, (int)newState); }