控制台应用程序C#的关闭事件 [英] Shutdown event for console application C#
本文介绍了控制台应用程序C#的关闭事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎么知道我的C#控制台应用程序何时停止?
How can i know when my C# console application will be stopping? Is there any event or like that?
谢谢!
推荐答案
使用应用程序域的 ProcessExit 事件
class Program
{
static void Main(string[] args)
{
AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit);
}
static void CurrentDomain_ProcessExit(object sender, EventArgs e)
{
Console.WriteLine("exit");
}
}
这篇关于控制台应用程序C#的关闭事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文