我有一个像C#这样的控制台程序
Class Program
{
static void main(string args[])
{
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想在main()退出后做一些事情.我试图为类程序编写一个解构函数,但它永远不会被击中.
有人知道怎么做.
非常感谢
Gon*_*alo 118
尝试以下的ProcessExit事件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");
}
}
Run Code Online (Sandbox Code Playgroud)