/// <summary> /// Clean up the socket(s). /// </summary> /// <param name="disposing">If set to <c>true</c> disposing.</param> protected virtual void Dispose(bool disposing) { // Already been here once. if (disposed) { return; } // This is only when manually calling dispose(), used to cleanup managed objects (things the GC knows about) if (disposing) { } // Cleanup any unmanaged objects (things like events, file handles, connections) here if (receiver != null) { receiver = null; } if (logRemoteSocket != null) { logRemoteSocket.Dispose(); logRemoteSocket = null; } // set the flag disposed = true; }
/// <summary> /// Instance this instance. /// </summary> public LogRemote(int port) { connectionPort = port; Log.OnForceVisionLogEvent += LogReceiver; logRemoteSocket = new LogRemoteSocket(OnAcceptConnection, connectionPort); AppDomain.CurrentDomain.UnhandledException += OnUnhandledException; }
/// <summary> /// Sends the message. /// </summary> /// <param name="str">The message to be sent through the socket connection.</param> private void SendMessage(string str) { string message = str + "\n"; if (receiver != null) { try { receiver.Send(System.Text.Encoding.UTF8.GetBytes(message)); } catch (SocketException) { QueueMessage(message); receiver.Disconnect(false); receiver = null; logRemoteSocket.Dispose(); logRemoteSocket = new LogRemoteSocket(OnAcceptConnection, connectionPort); } } else { QueueMessage(message); } }