public static void SetShouldDispose(BaseDisposable toDispose, bool value, bool callDispose = false) { if (IDisposedExtensions.IsNullOrDisposed(toDispose)) { return; } toDispose.ShouldDispose = value; if (callDispose) { toDispose.Dispose(); } }
internal void Resurrect(ref int managedThreadId) { //Need to retrieve the state from this instance. long state = 0; //Not already disposed or destructing? if (IsUndisposed.Equals(false) | BaseDisposable.IsDestructing(this, ref state).Equals(false)) { return; } //Check for a race condition or otherwise... if (managedThreadId.Equals(state >> 32)) { //Ressurection is possible and likely to succeed context from whence it was marked disposed. } /// }
internal static bool IsDestructing(BaseDisposable bd, ref long state) { return((state = RetrieveState(bd)) > Disposed); }
internal static long RetrieveState(BaseDisposable bd) { return(bd.State); }