I've read dozens of existing questions on here, they all come up with the same solutions, unfortunately none of these work. It seems they only work when the X button is clicked on a console application.
I am asking, is there a way to run some code when the console is forced closed? This means force closing the task in task manager, or the operating system froce closing it for any reason.
I've tried pretty much every existing solution on open questions of this site. This is not a duplicate. I repeat, this is not a duplicate. It's simply asking for something totally different.
Have I tried anything so far? No, I've tried all the usual, assigning a callback function to all kinds of events, but nothing actually works. I've done this before in a WinForm, but can't in console.