/// <summary> /// Closes the StartListenerAsync. /// </summary> public void Close() { if (_cts == null) { //Don't throw exception in this case, just ignore it :) return; //throw new InvalidOperationException("HttpListener is not running."); } Request = null; _cts.Cancel(); _cts = null; _isListening = false; _tcpListener.Stop(); try { // Stop task _listener.Wait(TimeSpan.FromMilliseconds(1)); } catch (Exception) { } }
/// <summary> /// Closes the listener. /// </summary> public void Close() { if (_cts == null) { throw new InvalidOperationException("HttpListener is not running."); } Request = null; _cts.Cancel(); _cts = null; _isListening = false; _tcpListener.Stop(); }
/// <summary> /// Closes the StartListenerAsync. /// </summary> public void Close() { if (_cts == null) { throw new InvalidOperationException("HttpListener is not running."); } _cts.Cancel(); _cts = null; _isListening = false; _tcpListener.Stop(); try { // Stop task _listener.Wait(TimeSpan.FromMilliseconds(1)); } catch (Exception) { } }