I have a little console C# program like
Class Program
{
static void main(string args[])
{
}
}
Now I want to do something after main() exit. I tried to write a deconstructor for Class Program, but it never get hit.
Does anybody know how to do it.
Thanks a lot
Try the ProcessExit event of AppDomain
:
using System;
class Test {
static void Main(string[] args)
{
AppDomain.CurrentDomain.ProcessExit += new EventHandler (OnProcessExit);
// Do something here
}
static void OnProcessExit (object sender, EventArgs e)
{
Console.WriteLine ("I'm out of here");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With