ElectronNET/Electron.NET

exe does not automatically exit when run from a Windows command prompt

Closed this issue · 2 comments

  • Target: .net 8, Node.js v20.19.0, running on Windows 10 x64

Steps to Reproduce:

  1. Clone the main branch https://github.com/ElectronNET/Electron.NET.git
  2. Open ElectronNET.sln in Visual Studio 2022 and Build in the Debug | Any CPU solution configuration.
  3. Open a new Windows Command Prompt
  4. Run cd .\src\ElectronNET.WebApp
  5. Run "..\ElectronNET.CLI\bin\Debug\net8.0\dotnet-electronize.exe" build /target win /dotnet-configuration Debug /p:SelfContained=false /p:BuildProjectReferences=false
  6. Run cd .\src\ElectronNET.WebApp\bin\Desktop\win-unpacked
  7. Run "ElectronNET API Demos.exe"
  8. Close the "ElectronNET API Demo" window
  9. Notice the process is still running and I have to press Ctrl+C to close the process.

The issue also occurs if I try to exit the program even before calling Electron.WindowManager.CreateWindowAsync.

I expected the process to exit when all windows are closed, since Electron.WindowManager.IsQuitOnWindowAllClosed is set to true by default.

If I double-click the exe from Windows Explorer, the issue doesn't occur.

As other issues mention, I even tried:

Electron.WindowManager.IsQuitOnWindowAllClosed = false;
Electron.App.WindowAllClosed += () => Electron.App.Exit();

browserWindow.OnClosed += () =>
{
    Electron.App.Exit(0);
    Environment.Exit(0);
    Electron.App.Quit();
};

Seems related, but the issues are closed, and don't mention running on the command line:
#68
#226
#338
#346
#364
#594

Image

Thank you.

It seems the exe actually exits, but the way the command prompt looks is misleading.

I found two "work-arounds" which make the command prompt behave as expected:

  1. Run set ELECTRON_NO_ATTACH_CONSOLE=1 before running the exe, but this prevents any output to be written to the console.
  2. Run cmd.exe /c ElectronApp.exe

Outdated - use ElectronNET.Core and ElectronNET.Core.AspNet.

See Wiki / What's New.