public void DisposedConditional(Action whenDisposed, Action whenNotDisposed)
 {
     if (_status == -1)
     {
         if (!ReferenceEquals(whenDisposed, null))
         {
             whenDisposed.Invoke();
         }
     }
     else
     {
         if (!ReferenceEquals(whenNotDisposed, null))
         {
             if (ThreadingHelper.SpinWaitRelativeSet(ref _status, 1, -1))
             {
                 try
                 {
                     whenNotDisposed.Invoke();
                 }
                 finally
                 {
                     global::System.Threading.Interlocked.Decrement(ref _status);
                 }
             }
             else
             {
                 if (!ReferenceEquals(whenDisposed, null))
                 {
                     whenDisposed.Invoke();
                 }
             }
         }
     }
 }
 public TReturn DisposedConditional <TReturn>(Func <TReturn> whenDisposed, Func <TReturn> whenNotDisposed)
 {
     if (_status == -1)
     {
         if (ReferenceEquals(whenDisposed, null))
         {
             return(default(TReturn));
         }
         else
         {
             return(whenDisposed.Invoke());
         }
     }
     else
     {
         if (ReferenceEquals(whenNotDisposed, null))
         {
             return(default(TReturn));
         }
         else
         {
             if (ThreadingHelper.SpinWaitRelativeSet(ref _status, 1, -1))
             {
                 try
                 {
                     return(whenNotDisposed.Invoke());
                 }
                 finally
                 {
                     global::System.Threading.Interlocked.Decrement(ref _status);
                 }
             }
             else
             {
                 if (ReferenceEquals(whenDisposed, null))
                 {
                     return(default(TReturn));
                 }
                 else
                 {
                     return(whenDisposed.Invoke());
                 }
             }
         }
     }
 }