From ff66d635aef9bcf21f30c7185348928d823f3fe9 Mon Sep 17 00:00:00 2001 From: "jeffery.thompson" Date: Tue, 18 Jul 2017 10:01:26 -0400 Subject: [PATCH] Fixed IcdTextWriter's IDisposable implementation --- ICD.Common.Utils/IO/IcdTextWriter.cs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/ICD.Common.Utils/IO/IcdTextWriter.cs b/ICD.Common.Utils/IO/IcdTextWriter.cs index c90eb81..75e5ed3 100644 --- a/ICD.Common.Utils/IO/IcdTextWriter.cs +++ b/ICD.Common.Utils/IO/IcdTextWriter.cs @@ -1,8 +1,10 @@ using System; #if SIMPLSHARP using Crestron.SimplSharp.CrestronIO; +using GC = Crestron.SimplSharp.CrestronEnvironment.GC; #else using System.IO; +using GC = System.GC; #endif namespace ICD.Common.Utils.IO @@ -13,6 +15,8 @@ namespace ICD.Common.Utils.IO public TextWriter WrappedTextWriter { get { return m_TextWriter; } } + private bool disposed = false; + /// /// Constructor. /// @@ -27,12 +31,25 @@ namespace ICD.Common.Utils.IO ~IcdTextWriter() { - Dispose(); + Dispose(false); } public void Dispose() { - m_TextWriter.Dispose(); + Dispose(true); + GC.SuppressFinalize(this); + } + + protected void Dispose(bool disposing) + { + if (disposed) + return; + + if (disposing) + { + m_TextWriter.Dispose(); + } + disposed = true; } } }