private async Task StartConnectionListener() { // Wait for a connection HttpListenerContext context = null; try { OnRestServerStarted?.Invoke(this, new OnRestServerStartedEventArgs(m_RestServerData)); context = await listener.GetContextAsync(); } catch (ObjectDisposedException) { //closing if (m_IsCloseRequested) { return; } if (context == null) { TraceWriteLine($"Rest Server {m_ServerName}, Failed to get http context from request"); return; } } // Allow a new connection listener to be set up. int semCount = sem.Release(); //Trace.WriteLine($"Rest Server {m_ServerName} listener connection with semaphore instance count at {semCount}"); //process the current request Thread processThread = new Thread(() => { // m_ActiveRequests will keep track of currently active requests for the purposes of shuting down cleanly m_ActiveRequests++; try { ProcessRequest(context); } catch (Exception ex) { TraceWriteLine(ex.ToString()); } finally { m_ActiveRequests--; } }); processThread.Start(); }
private void RestServer_OnRestServerStarted(object sender, OnRestServerStartedEventArgs e) { OnRestServerStarted?.Invoke(this, e); }