private void ConnectionManagerThreadStart()
{
Interlocked.Exchange(ref _runState, (long)State.Starting);
try
{
if (!_listener.IsListening)
{
_listener.Start();
}
if (_listener.IsListening)
{
Interlocked.Exchange(ref _runState, (long)State.Started);
}
try
{
while (RunState == State.Started)
{
HttpListenerContext context = _listener.GetContext();
RaiseIncomingRequest(context);
}
}
catch (HttpListenerException)
{
// This will occur when the listener gets shut down.
// Just swallow it and move on.
}
}
finally
{
Interlocked.Exchange(ref _runState, (long)State.Stopped);
}
}