Skip to content

Commit

Permalink
Restart input listener if connection was dropped #3249
Browse files Browse the repository at this point in the history
  • Loading branch information
seerge committed Oct 13, 2024
1 parent 0d3332f commit 1cca7a5
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/Input/KeyboardListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class KeyboardListener
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
Action<int> _handler;

static int retry = 0;

public KeyboardListener(Action<int> KeyHandler)
{
_handler = KeyHandler;
Expand Down Expand Up @@ -67,6 +69,12 @@ private void Listen()
catch (Exception ex)
{
Logger.WriteLine($"Listener exited: {ex.Message}");
if (retry++ < 2)
{
Thread.Sleep(300);
Logger.WriteLine($"Restarting listener {retry}");
Listen();
}
}

}
Expand Down

0 comments on commit 1cca7a5

Please sign in to comment.