How to shutdown local tomcat server when closing browser window? - visual-studio

I hava a web app running on a local tomcat server.
When the user starts the app (via desktop shortcut) the server starts and the app is opened in a browser window.
But when the user just clicks on the close button to stop the application the server is still running in the background - that's annoying.
I tried to utilize the "unonload" and "onbeforeunload" events from javascript but unfortunately these events are also fired on some other requests in the app.
So I can't use them, except I do a lot of refactoring.
Does anyone have an idea for a possible solution?
Btw, what I find interesting is the behaviour of Visual Studio when debugging a web application. When I close the browser window Visual Studio also gets a trigger to stop debug mode. So it seems it somehow notices the close event of the browser window, which would be exactly what I need. But I don't know how they do it...

Can you wrap the starting of Tomcat and launching your app in a batch file or shell script? (Not sure what your target OS is...)
The script/batch file would start Tomcat and then launch your application. When the user exits your application, the script/batch file would then shut down Tomcat.

You can setup a short session timeout, and use a HttpSessionListener. On sessionDestroyed(..) you can stop tomcat (using catalina.bat for example) .
Otherwise you can try to detect browser close, and send a shutdown message to the server using ajax (before the browser is closed).

Related

Erlang wxWidgets app - Closing the beam.smp file once app finished

got a weird question which I haven't been able to find an answer to online so I'm trying my luck here.
I have a normal erlang application using wxWidgets, once I try to shut down my application I get the event that the wxServer has indeed entered the event which is connected to the window closing, I get a message that it is in the process of exiting, and my window does indeed close, but as shown in the picture below, the beam.smp on my toolbar doesn't close at all, I have to manually force the closing of the beam.smp file which sends a SIGTERM to the erlang terminal which also shuts down my erlang VM (which I have to reboot it later).
long story short, what am I missing on my close window event so that everything shuts down nicely without it crashing my erlang VM? I was able to read that wxWidgets behaves differently on macOS but I haven't been able to find how to correctly close the application.
handle_event(#wx{event = #wxClose{}},State = #state{frame = Frame,panel = Panel}) ->
io:format("Exiting~n"),
wxFrame:close(Frame),
wxFrame:destroy(Frame),
wx:destroy(),
{stop,normal,State};
You can close the emulator from code with init:stop/0,1
Also, if your application is started as permanent, it should suffice with terminating that application. Check the behaviour in erlang:application

VS2013 won't debug a specific web application

I have a web application that uses IIS, but when I try to debug it VS just locks up and gives me the hour glass cursor icon. No browser window opens, nor does an instance pop up in the Task Manager. VS says its Running / not "Not Responding", but I cannot interact with the IDE. Can't Ctrl-Break to stop or anything.
I was able to run it before, and I'm not aware of any system or IIS changes that could cause this. I've disabled source control and I've tried launching the app in both Chrome and IE but it still behaves the exact same way as described above.
Has anyone else encountered this? The only threads I could find just describe general slowness in the IDE but otherwise its functional. The recommended fix was to disable the source control functionality, which as I said I already tried.
I should note that I don't seem to have an issue running & debugging winforms applications. I also just created a web application and was able to launch it in Chrome and get to the homepage. Also, it doesn't make a difference if I have a breakpoint set or not.
This solution has 4 different projects. If I set a different project as the Startup Project, it does run and launches the browser but it just gives me a 'file explorer' sort of view where it just lists the files in that project's directly which is obviously not what I want.
Edit; If I manually open a browser tab, try to navigate to http://localhost/myApplication, VS pops up and asks if I want to attach process w3wp.exe to IIS APPPOOL\myAppPool. If I attach, it opens a new tab in Chrome and my application runs. But unless I do these 2 steps, it does not run.

How to capture exiting of Qt Application when shut down by debugger?

I am developing a GUI application in Qt 4.8.4 with Visual Studio 2010. I need to perform some cleanup work before my application closes so I have reimplemented the QWidget closeEvent in my MainWindow class to capture when the user either clicks X or when they select File->Exit from the menu. That works fine. The problem however is when I am running the application in the VS debugger and I use the debugger to shut down the application the close event doesn't get triggered. I can always just shutdown my application by clicking File->Exit or clicking X but sometimes I forget and shut down the debugger instead so it's really more of an annoyance. Is there a way to capture when the debugger shuts down my application?
Not that I know of.
The logic of it: the debugger is running a sandbox, and when it shuts down, the sandbox gets freed. Your application is running inside that sandbox - so when that sandbox gets freed/closed/destroyed, your app simply vanishes without any cleanup.

Application window getting hide

I have done multi threaded MFC application. App is running fine, but after some time PC window gets logged off with the given password to log in the PC. My application does not appear anywhere but process is running.
What could be the reason for this behavior?

windows service server crashes

I have created windows service via Visual Studio.
The service is running ftp server.
I have the same program in .exe app which works perfectly fine.
However, the service crashes in after a while.
I doesn't even get into the OnStop/OnShutdown event, just stops working.
Any ideas?
After doing this myself recently, here is a way of making sure the service restarts after its own crash:
Go to Start - > Control Panel and select Administrative tools in the window. Then, select services and right click on the service you'd like to customize. Under the recovery tab you can set the first failure to restart the service, along with the second and subsequent failures. I hope this helps you out!

Resources