Getting back focus after child process spawn


#1

I use child_process spawn to start a new C# console app within my electron app. This new app then gets focus and the focus never returns to the electron app. What I would want to do is - when the C# app finishes its data collection and starts the data processing - to switch focus to the electron app and display a message there to wait , and then when the C# app is done, to have the electron app be notified again and change state to show that the C# app is done and where to find the resulting collection files.

Is there an electron API that would allow me to do this? Any pointers to docs would be great!

Let me know if you need more details as I didn’t know exactly what to provide. Or if the topic already exists (I searched but couldn’t find something similar)

Thanks!


#2

If your C# app was just a console app you could’ve communicated with it via stdin/stdout, but since it’s a GUI app you have to use another form of IPC, ideally a named pipe on Windows and domain sockets on macOS & Linux. In your Electron app you can use Node’s net module to create/listen to a named pipe/domain socket, in your C# app you can use NamedPipeServerStream and NamedPipeClientStream from the System.IO.Pipes namespace. One of your apps will need to create the named pipe (the server), and the other one will need to connect to it, it’s probably easier to set up your Electron app to be the server (here’s an example) and your C# app to be the client.


#3

Thanks a lot!