public void Stop() { try { if (Running) { bool b = true; if (BeforeStopEvent != null) { b = BeforeStopEvent(); } if (b) { if (UDPListeners != null) { while (UDPListeners.Count > 0) { System.Threading.Thread thread = UDPListeners[0]; if (thread.IsAlive) { thread.Abort(); while (thread.IsAlive) { System.Threading.Thread.Sleep(250); } } UDPListeners.Remove(thread); } } if (TCPListeners != null) { while (TCPListeners.Count > 0) { System.Threading.Thread thread = TCPListeners[0]; if (thread.IsAlive) { thread.Abort(); while (thread.IsAlive) { System.Threading.Thread.Sleep(250); } } TCPListeners.Remove(thread); } } Running = false; if (AfterStopEvent != null) { AfterStopEvent(); } } } } catch (System.Exception ex) { throw ex; } }