don't error when stopping
This commit is contained in:
@@ -17,6 +17,7 @@ public class ApiServer(string apiUrl) : IApiServer
|
||||
protected int restartAttempts = 0;
|
||||
protected DateTime lastRestartAttempt;
|
||||
protected SemaphoreSlim? semaphore;
|
||||
protected bool doListen;
|
||||
|
||||
public event OnCheckAuthenticationEventHandler? OnCheckAuthentication;
|
||||
public event OnCheckContextEventHandler? OnCheckContext;
|
||||
@@ -52,6 +53,7 @@ public class ApiServer(string apiUrl) : IApiServer
|
||||
{
|
||||
Log.Info("Starting listener");
|
||||
httpListener.Prefixes.Add(ApiUrl + "/");
|
||||
doListen = true;
|
||||
httpListener.Start();
|
||||
Log.Info("Started listener");
|
||||
Receive();
|
||||
@@ -60,6 +62,7 @@ public class ApiServer(string apiUrl) : IApiServer
|
||||
public virtual void Stop()
|
||||
{
|
||||
Log.Info("Stopping listener");
|
||||
doListen = false;
|
||||
httpListener.Stop();
|
||||
Thread.Sleep(StopDelay);
|
||||
httpListener.Close();
|
||||
@@ -181,7 +184,7 @@ public class ApiServer(string apiUrl) : IApiServer
|
||||
HttpListenerContext? context;
|
||||
|
||||
// Skip if not lisstening anymore
|
||||
if (!httpListener.IsListening)
|
||||
if (!httpListener.IsListening || !doListen)
|
||||
return;
|
||||
|
||||
// Wait for a free slot
|
||||
|
||||
Reference in New Issue
Block a user