private void StartListening() { Sea = new SocketAsyncEventArgs(); AcceptReset.Reset(); Sea.Completed += (s, a) => { HandleSocket(Sea.AcceptSocket); AcceptReset.Set(); }; try { if (!ListenSocket.AcceptAsync(Sea)) { AcceptReset.Set(); HandleSocket(Sea.AcceptSocket); } } catch (Exception ex) { OnLog(ex.ToString()); } AcceptReset.WaitOne(); Sea.Dispose(); }
public void Stop() { IsRunning = false; AcceptReset.Set(); MainThread.Join(); }