From 80414ffe1788a8b9de18e38734544173db902015 Mon Sep 17 00:00:00 2001 From: fcolin Date: Sun, 18 Mar 2012 17:29:48 +0000 Subject: Dispose rules detected by VS2011 --- Ivy/Ivy.cs | 30 +++++++++++++++++++++++++-- Ivy/IvyTCPStreamV3.cs | 5 +++-- Ivy/IvyWatcher.cs | 56 +++++++++++++++++++++++++-------------------------- 3 files changed, 59 insertions(+), 32 deletions(-) diff --git a/Ivy/Ivy.cs b/Ivy/Ivy.cs index 0b1818a..9344ca9 100644 --- a/Ivy/Ivy.cs +++ b/Ivy/Ivy.cs @@ -27,7 +27,7 @@ namespace IvyBus /// The Main bus Class /// /// - public class Ivy + public class Ivy : IDisposable { /* Event */ /// @@ -1410,5 +1410,31 @@ namespace IvyBus return valid; } - } + + #region IDisposable Membres + // needed by tcplistener_running + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + // Free other state (managed objects). + if (tcplistener_running != null) + { + tcplistener_running.Close(); + tcplistener_running = null; + } + } + // Free your own state (unmanaged objects). + // Set large fields to null. + + } + + #endregion + } } \ No newline at end of file diff --git a/Ivy/IvyTCPStreamV3.cs b/Ivy/IvyTCPStreamV3.cs index aa76e93..00e8688 100644 --- a/Ivy/IvyTCPStreamV3.cs +++ b/Ivy/IvyTCPStreamV3.cs @@ -23,6 +23,7 @@ namespace IvyBus private StreamReader input; private StreamWriter output; private IvyProtocol receiver; + private Object outputLock = new Object(); internal IvyTCPStreamV3(Socket socket, IvyProtocol receiver) : base(socket) { @@ -67,8 +68,8 @@ namespace IvyBus private void SendMsg(MessageType msgType, int msgId, string msgData) { - // IOException Should be traited upstairs - lock (this.output) + // IOException Should be traited upstairs + lock (this.outputLock) { this.output.Write((int)msgType); this.output.Write(' '); diff --git a/Ivy/IvyWatcher.cs b/Ivy/IvyWatcher.cs index f239b99..630472d 100644 --- a/Ivy/IvyWatcher.cs +++ b/Ivy/IvyWatcher.cs @@ -26,7 +26,7 @@ namespace IvyBus /// that the broadcast is done using the same socket, which is not a good /// thing. /// - internal class IvyWatcher //: IDisposable + internal class IvyWatcher : IDisposable { private Ivy bus; /* master bus controler */ private int port; @@ -194,32 +194,32 @@ namespace IvyBus stream.sendMsg(EPhost, bus.applicationPort, bus.AppId, bus.AppName);// notifies our arrival on each domain: protocol version + port } } - // Not needed for pure managed object ??!!! - - //#region IDisposable Membres - - //public void Dispose() - //{ - // Dispose(true); - // GC.SuppressFinalize(this); - //} - - //protected virtual void Dispose(bool disposing) - //{ - // if (disposing) - // { - // // Free other state (managed objects). - // if (stream != null) - // { - // stream.Close(); - // stream = null; - // } - // } - // // Free your own state (unmanaged objects). - // // Set large fields to null. - - //} - - //#endregion + // needed for IvyUDPStreamV4', 'IvyUDPStreamV3 managed object ??!!! + + #region IDisposable Membres + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + // Free other state (managed objects). + if (stream != null) + { + stream.Close(); + stream = null; + } + } + // Free your own state (unmanaged objects). + // Set large fields to null. + + } + + #endregion } } \ No newline at end of file -- cgit v1.1