C# program exits immediately if UseWPF/UseWindowsForms set to true

Breaking change in .NET 5.

MS Docs:

OutputType is automatically set to WinExe for Windows Presentation Foundation (WPF) and Windows Forms apps. When OutputType is set to WinExe, a console window doesn't open when the app is executed.

(...)

Recommended action

No action is required in your part. However, if you want to revert to the old behavior, set the DisableWinExeOutputInference property to true in your project file.

<DisableWinExeOutputInference>true</DisableWinExeOutputInference>

Your app is quitting because there is no standard input to use ReadLine() on.