internal void Dispose(bool disposing) { if (dc != null) { DbgUtil.AssertFinalization(this, disposing); try { // Restore original dc. dc.RestoreHdc(); if (disposeDc) { dc.Dispose(disposing); } if (graphics != null) // if created from a Graphics object... { graphics.ReleaseHdcInternal(dc.Hdc); graphics = null; } } catch (Exception ex) { if (ClientUtils.IsSecurityOrCriticalException(ex)) { throw; // rethrow the original exception. } Debug.Fail("Exception thrown during disposing: \r\n" + ex.ToString()); } finally { dc = null; } } }