Microsoft.Protocols.TestTools.StackSdk.CommonStack.HttpServerTransport.StopHttpServer C# (CSharp) Method

StopHttpServer() public method

Stop http server to listen and receive the http request.
public StopHttpServer ( ) : void
return void
        public void StopHttpServer()
        {
            Interlocked.Exchange(ref this.runState, (long)State.Stopping);

            if (this.httpListener.IsListening)
            {
                this.httpListener.Stop();
            }

            if (!this.httpListener.IsListening && this.logger != null)
            {
                this.logger.AddDebug("Http server process is stopped listening successfully.");
            }

            // Wait for 10 seconds.
            long waitMilliseconds = 10000;
            DateTime startTime = DateTime.Now;

            while (this.RunState != State.Stopped)
            {
                Thread.Sleep(100);
                if ((DateTime.Now - startTime).TotalMilliseconds > waitMilliseconds)
                {
                    throw new TimeoutException("Unable to stop the http server process.");
                }
            }

            this.httpRequestManagerThread = null;

            if (this.logger != null)
            {
                this.logger.AddDebug("Http server process is stopped successfully.");
            }
        }