Search code examples
c#asp.net-corecefsharp

How to start/call an Asp.net core app when i open CefSharp(winform) browser and close it on exit?


Tools used: Visual Studio 2019, Asp.net core 5.0, CefSharp.WinForms v79.0

I have created an asp.net core app and a CefSharp browser.

If i click on the app.core and then on the browser it works fine.

I would like to some kind "automate" the whole process.

How to start the Asp.net core app before the CefSharp fully loads/starts.

Can this be done from within the CefSharp browser,

so it opens the app.core in automatic and closes it too when CefSharp is closed?

i can already do this by cmd-line :

tasklist /fi "imagename eq APP.exe" |find ":" > nul

if errorlevel 1 taskkill /F /IM "APP.exe"

start C:\Server\APP.exe 

start C:\CEFSHARP\GUI.exe

Solution

  • You can start and stop process "C:\Server\APP.exe" from within GUI.EXE - this is assuming that you have a source code for GUI.EXE

    You need to do the following in GUI.EXE source code (here I'm assuming that you are using Windows Forms application):

    1. Add a Load event handler to your main form. From within your event handler you will need to start "C:\Server\APP.exe". You can use System.Diagnostics.Process.Start(@"C:\Server\APP.exe"); within event handler to start a process. Note that this method will return Process object which can be used to close the application.
    2. Add a Closing event handler to your main form. From within your event handler you will need to stop "C:\Server\APP.exe" You can do this via CloseMainWindow method of the Process object.