private void CloseOrError(bool error) { bool doEvent = false; lock (this) { if (!cleanUp) { doEvent = !cleanUp; SocketExtension.Close(socket); cleanUp = true; } } if (doEvent) { if (error) { DoError(new ErrorEventArgs()); } else { DoClose(new CloseEventArgs()); } } }
public void Stop() { lock (this) { if (server != null) { SocketExtension.Close(server); server = null; } } }