private void Dispose(bool disposing) { PtsContext ptsContext = null; // Do actual dispose only once. if (Interlocked.CompareExchange(ref _disposed, 1, 0) == 0) { // Dispose PTS break record. // According to following article the entire reachable graph from // a finalizable object is promoted, and it is safe to access its // members if they do not have their own finalizers. // Hence it is OK to access _ptsContext during finalization. // See: http://blogs.msdn.com/[....]/archive/2004/02/20/77460.aspx ptsContext = _ptsContext.Target as PtsContext; if (ptsContext != null && !ptsContext.Disposed) { // Notify PtsContext that BreakRecord is not used anymore, so all // associated resources can by destroyed. ptsContext.OnPageBreakRecordDisposed(_br, disposing); } // Cleanup the state. _br.Value = IntPtr.Zero; _ptsContext = null; } }
private void Dispose(bool disposing) { if (Interlocked.CompareExchange(ref this._disposed, 1, 0) == 0) { PtsContext ptsContext = this._ptsContext.Target as PtsContext; if (ptsContext != null && !ptsContext.Disposed) { ptsContext.OnPageBreakRecordDisposed(this._br, disposing); } this._br.Value = IntPtr.Zero; this._ptsContext = null; } }