title: C# how to receive system close or exit events in a commandline application
body: <p>I'm trying, but everything I've found so far seems to centre around GUI's and form apps. That is not what I'm using.</p>
  
  <p>Eventually it'll be a service, but till it is done I'm running it as a normal app, the problem being that if I just close it by accident, it'll leave another service hanging for up to 30 minutes with bad data. I though it would be easy to add a listener to catch the app being closed.</p>
  
  <p>But I just can't figure it out.</p>