471,336 Members | 1,427 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,336 software developers and data experts.

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

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
Jun 27 '08 #1
4 1027
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?
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()).
--
Martijn
Jun 27 '08 #2
On May 18, 11:12 am, "Martijn"
<subscription_REMOVE_101@hot_REMOVE_mail.comwrot e:
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?
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()).

--
Martijn
Thanks for your quick response.

The program is a forms based program, not a console.
Thanks!
Jun 27 '08 #3
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
Jun 27 '08 #4
On May 18, 4:31 pm, Marc Gravell <marc.grav...@gmail.comwrote:
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!
Jun 27 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Jim Steinberger | last post: by
1 post views Thread by Donkey Cart Racer | last post: by
1 post views Thread by =?Utf-8?B?RW5naW5lZXJpaw==?= | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.