Skip to content

Commit

Permalink
Merge pull request #179 from ptr727/keyboard-quit
Browse files Browse the repository at this point in the history
Test if there is an interactive console
  • Loading branch information
ptr727 authored Jun 21, 2023
2 parents a1a2d50 + dda37b0 commit ceb92eb
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions PlexCleaner/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ private static int Main()
WaitForDebugger();

// Register cancel and keyboard handlers
Console.CancelKeyPress += CancelEventHandler;
var consoleKeyTask = Task.Run(KeyPressHandler);
Console.WriteLine("Press Ctrl+C or Ctrl+Z or Ctrl+Q to exit.");
Task consoleKeyTask = null;
if (Environment.UserInteractive)
{
Console.CancelKeyPress += CancelEventHandler;
consoleKeyTask = Task.Run(KeyPressHandler);
Console.WriteLine("Press Ctrl+C or Ctrl+Z or Ctrl+Q to exit.");
}

// Create default logger
CreateLogger(null);
Expand All @@ -51,7 +55,7 @@ private static int Main()

// Cancel background operations
Cancel();
consoleKeyTask.Wait();
consoleKeyTask?.Wait();

// Stop the timer
keepAwakeTimer.Stop();
Expand Down

0 comments on commit ceb92eb

Please sign in to comment.