Fix catching listener exceptions
This commit is contained in:
parent
c9f11aa285
commit
0d1d5c6490
15
Ooui/UI.cs
15
Ooui/UI.cs
|
@ -177,6 +177,7 @@ namespace Ooui
|
||||||
static async Task RunAsync (string listenerPrefix, CancellationToken token)
|
static async Task RunAsync (string listenerPrefix, CancellationToken token)
|
||||||
{
|
{
|
||||||
HttpListener listener = null;
|
HttpListener listener = null;
|
||||||
|
var wait = 5;
|
||||||
|
|
||||||
started.Reset ();
|
started.Reset ();
|
||||||
while (!started.WaitOne(0) && !token.IsCancellationRequested) {
|
while (!started.WaitOne(0) && !token.IsCancellationRequested) {
|
||||||
|
@ -186,12 +187,18 @@ namespace Ooui
|
||||||
listener.Start ();
|
listener.Start ();
|
||||||
started.Set ();
|
started.Set ();
|
||||||
}
|
}
|
||||||
catch (System.Net.Sockets.SocketException ex) when
|
catch (System.Net.Sockets.SocketException ex) {
|
||||||
(ex.SocketErrorCode == System.Net.Sockets.SocketError.AddressAlreadyInUse) {
|
Console.WriteLine ($"{listenerPrefix} error: {ex.Message}. Trying again in {wait} seconds...");
|
||||||
var wait = 5;
|
|
||||||
Console.WriteLine ($"{listenerPrefix} is in use, trying again in {wait} seconds...");
|
|
||||||
await Task.Delay (wait * 1000).ConfigureAwait (false);
|
await Task.Delay (wait * 1000).ConfigureAwait (false);
|
||||||
}
|
}
|
||||||
|
catch (System.Net.HttpListenerException ex) {
|
||||||
|
Console.WriteLine ($"{listenerPrefix} error: {ex.Message}. Trying again in {wait} seconds...");
|
||||||
|
await Task.Delay (wait * 1000).ConfigureAwait (false);
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
Error ("Error listening", ex);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Console.ForegroundColor = ConsoleColor.Green;
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
Console.WriteLine ($"Listening at {listenerPrefix}...");
|
Console.WriteLine ($"Listening at {listenerPrefix}...");
|
||||||
|
|
Loading…
Reference in New Issue