/// <summary> /// Implements the listening thread. /// </summary> private void ListenLoop() { EnhancedSocket sockListen = sockParam; EnhancedSocket sockAccept; try { threadStart.Set(); // Indicate that we have the socket parameter // Loop forever or until we get an exception. This thread is // terminated by closing the listening socket which will cause // Accept() to throw an exception. while (true) { try { sockAccept = sockListen.Accept(); if (sockAccept == null) { return; } // Queue the accept so that further processing will happen // on a pool thread, leaving this thread free to accept // additional incoming connections. ThreadPool.UnsafeQueueUserWorkItem(onAccept, new object[] { sockAccept, sockListen.LocalEndPoint }); } catch { return; } } } catch (SocketClosedException) { // Ignore these } catch (Exception e) { SysLog.LogException(e); } }