控制台应用程序 C# 的关闭事件 [英] Shutdown event for console application C#

查看:21
本文介绍了控制台应用程序 C# 的关闭事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何知道我的 C# 控制台应用程序何时停止?有什么活动之类的吗?

How can i know when my C# console application will be stopping? Is there any event or like that?

谢谢!

推荐答案

使用ProcessExit 应用程序域的事件

Use ProcessExit event of the application domain

   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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆