Function that's triggered when/before the application closes?

  • Thread starter Thread starter Matt Brown - identify
  • Start date Start date
M

Matt Brown - identify

Hello,

I've got some code that I'd like to have execute right before the
application closes, but can't figure out which function to use to do
this.

Much similar to the form_closing function, I'd like to make sure that
the code is executed whenever and however the user exits the
application (specifically... it's UnregisterHotKey()).


Thanks!

Matt
 
Hi Matt,
I've got some code that I'd like to have execute right before the
application closes, but can't figure out which function to use to do
this.

Is this a console application (your 2nd section below may indicate this), or
are you simply implying any application in general?
 
Hi Matt,


Is this a console application (your 2nd section below may indicate this), or
are you simply implying any application in general?

Thanks for your quick response.

The program is a forms based program, not a console.


Thanks!
 
Well, assuming you aren't doing anything too funky with threading, how
about just having a "finally" block in your Main() method?

Note that it still can't cope with anything too brutal like a process
kill, and a few fairly terminal exceptions... but:

static void Main(string[] args)
{
try
{
// your app code here
}
finally
{
// your cleanup code here
}
}

Marc
 
Well, assuming you aren't doing anything too funky with threading, how
about just having a "finally" block in your Main() method?

Note that it still can't cope with anything too brutal like a process
kill, and a few fairly terminal exceptions... but:

static void Main(string[] args)
{
try
{
// your app code here
}
finally
{
// your cleanup code here
}
}

Marc

No crazy threading... this will work fine! Thanks!
 
Back
Top