System.Threading.AtomicBooleanValue.TryRelaxedSet C# (CSharp) Method

TryRelaxedSet() public method

public TryRelaxedSet ( ) : bool
return bool
		public bool TryRelaxedSet ()
		{
			return flag == UnSet && !Exchange (true);
		}

Usage Example

        protected virtual void Dispose(bool disposing)
        {
            if (!disposed.TryRelaxedSet())
            {
                return;
            }

            if (handle != null)
            {
                var tmpHandle = Interlocked.Exchange(ref handle, null);
                if (used > 0)
                {
                    // A tiny wait (just a few cycles normally) before releasing
                    SpinWait wait = new SpinWait();
                    while (used > 0)
                    {
                        wait.SpinOnce();
                    }
                }
                ((IDisposable)tmpHandle).Dispose();
            }
        }