/// <summary> /// TBD /// </summary> /// <param name="from">TBD</param> /// <param name="action">TBD</param> /// <returns>TBD</returns> protected bool TranscendFrom(bool from, Action action) { lock (_lock) { if (_switch.CompareAndSet(from, !from)) { try { action(); } catch (Exception) { _switch.CompareAndSet(!from, from); // revert status throw; } return(true); } return(false); } }
public void Close() { if (closed.CompareAndSet(false, true)) { socket.Close(); if (System.Threading.Thread.CurrentThread != readThread) { readThread.Join(); } socketWriter.Close(); socketReader.Close(); } }