Rob*_*ert 7 c# events .net-4.0 console-application event-handling
我怎么知道我的C#控制台应用程序什么时候停止?有没有这样的事件?
谢谢!
Hab*_*bib 25
使用应用程序域的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");
}
}
Run Code Online (Sandbox Code Playgroud)
处理此事件System.Console.CancelKeyPress
可能对您有所帮助.
MSDN解释了如何处理此事件以及处理此事件时需要处理的其他事项,摘录如下:
此事件与System.ConsoleCancelEventHandler和System.ConsoleCancelEventArgs一起使用.CancelKeyPress事件使控制台应用程序能够拦截CTRL + C信号,以便应用程序可以决定是继续执行还是终止.
使用此事件可以显式控制应用程序响应CTRL + C信号的方式.如果您的应用程序具有简单的要求,则可以使用TreatControlCAsInput属性而不是此事件.
此事件的事件处理程序在线程池线程上执行.
归档时间: |
|
查看次数: |
11570 次 |
最近记录: |