mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-02-03 21:25:13 +00:00
Dangling Electron Processes #1036
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @AeonSake on GitHub (Dec 12, 2025).
Whenever the main application exits unexpectedly or before the electron window is shown (e.g., by returning before building/running the
WebApplicationinstance), a few electron processes will remain running (usually 4, 1 main process, 3 sub-processes). It would be great if all dangling electron process would be killed once the main C# process exits. It looks like the main electron process is not always listening for the exit of the C# process?@softworkz commented on GitHub (Dec 12, 2025):
That's more a flaw of the original design than a bug.
I can only recommend to try dotnet-first instead: https://github.com/ElectronNET/Electron.NET/wiki/Startup-Methods
What you are describing is the exact reason why this new mode exists: While there may be some improvements possible, the classic "electron-first" approach will never be 100% reliable and solid.
@AeonSake commented on GitHub (Dec 12, 2025):
Is it possible to force the .NET-first mode without the process argument? Where can I get the electron port at runtime, or is it always hard-coded to 8001? Can this mode somehow be set as default for publishing?
@softworkz commented on GitHub (Dec 12, 2025):
I believe that I made it work for ASP.Net as well, don't remember atm, but at least with console projects, You can just start either this or that.
@AeonSake commented on GitHub (Dec 13, 2025):
I might not understand this properly, but that doesn't work in the packaged variant...right? So I probably need to package the application myself to make it work; or is there a way to start the ASP.NET executable instead of the electron one from the package itself?
@softworkz commented on GitHub (Dec 14, 2025):
You don't need manual packaging, but adjustments are needed indeed.
It depends on the target platform, but here's how I'm doing it for Linux:
Add a stub file to the root of the project
Name it like the electron executable would normally be named with an underscore suffix.
So, if it would be
my.project, name itmy.project_Set "Build Action" to "Content" and "Copy if newer"
Add an
Assets/afterpack.jsfileand set "Build Action" to "None" and "Copy to output directory" to "Copy if newer"
In the .csproj file
add this, to tell Electron.NET the new name of the electron executable:
In electron-builder.js
add this, to tell Electron.NET the new name of the electron executable:
NOTES
I had to do it like this, because I also have the requirement that the working directory on launch is
./bin/resources(for native library resolution).This is for Linux. It works with all packaging types, but For Windows, you'd need to adapt it accordingly.
There might be easier ways!
electron-builder options
Please consult the electron-builder documentation at: https://www.electron.build/win to look for other ways to get it done.
Hook Scripts
In the same way like
afterPack, you can use other hook scripts likeartifactBuildStarted,artifactBuildCompletedorbeforePack.The following pattern is invaluable for figuring out what's available in the various hooks:
...because
JSON.stringify()doesn't work due to recursions.@AeonSake commented on GitHub (Dec 14, 2025):
Unfortunately, calling the .NET executable first also always opens the console. Is there a way to hide it entirely?
@softworkz commented on GitHub (Dec 14, 2025):
Add this to the csproj file (if targeting Windows):
Or rather search for a
OutputTypeproperty first and change that. If you target other platforms, make it conditional.@AeonSake commented on GitHub (Jan 2, 2026):
@softworkz unfortunately that doesn't work. Setting that will break the entire application for some reason, even while debugging. The SingalR circuit never gets created and except the initial static render (and any other static files), any Blazor/Server interaction won't work.