namespace RealTimeGraphEx.DX2D { using System; public static class Disposer { /// /// Dispose an object instance and set the reference to null /// /// The type of object to dispose /// A reference to the instance for disposal /// This method hides any thrown exceptions that might occur during disposal of the object (by design) public static void SafeDispose(ref T resource) where T : class { if (resource == null) { return; } var disposer = resource as IDisposable; if (disposer != null) { try { disposer.Dispose(); } catch { } } resource = null; } } }