Is there a way to 'catch' the application restart when using 'dotnet watch'? - .net-5

I've got a .net5 webapi application and I have registered a handler via appLifetime.ApplicationStopping.Register() that will do some cleanup activities.
If I run my application via dotnet watch, and subsequently press Ctrl-C, the cleanup handler will be called as expected.
However, if I save one of the application source files and dotnet watch restarts my application, my cleanup handler is not called.
Is there any way to get my cleanup code called automatically when dotnet watch (or any other container) restarts my application?

Related

Complete Task After Quit (Prevent Stopping Task when app Quit)

I want yo make a task which complete running after Quit the app. Like complete Downloading Task. I don't find active way or method for Xamarin form mobile app. Any Help?
All You Want to Do is You Want your Task Run in Background so Even if you Quit the App the Task continues to Run is it okie ?
This Type of Task Are Known As Services(Back ground Tasks,or Background Services) in .net And Xamarin PlatForms
I Think You will Find This link Helpfull
See this : enter link description here
in this Way if you are running Some Downoading Task then it will not be killed After App is Getting quit or onSleep and will keep running in Back Ground Until Its Completed Or Any Error Generate ..
First, if you want to make the app still be running after quitting, It can not be realized.
Second, if you want to make the app quit after finishing the task you can refer to the How to terminate a Xamarin application?

How to register app launch listener in javascript for automation

I'm trying to build a script with javascript for automation to prevent certain applications from launching in OSX. In the documentation, there is a NSWorkspaceWillLaunchApplicationNotification notification. How can I listen for this notification, check which application is being launched, and then stop the application from launching?
I'd like to be able to do it programmatically because I'm building an app for people to be able to block timewasting applications while they're working.

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.

How to avoid the message "The app didn't start in the required time." while a debugger is attached?

I'd like to debug a Windows Store App, but when I attach a debugger the app is quickly killed and I get the message "The app didn't start in the required time."
How do you debug a running Windows Store App if Windows is going to kill the app as soon as you break in the debugger?
The command line tool PLMDebug, which is part of the Debugging Tools for Windows package, can be used to exempt an app from the Process Lifetime Management (PLM) policies. When put into debug mode, an app will not be subject to termination and will not be automatically suspended.
Usage:
plmdebug /enableDebug <PackageFullName> [OptionalDebuggerCommandLine]

How to shutdown local tomcat server when closing browser window?

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).

Resources