C#ProcessExit事件处理程序不触发代码

时间:2015-10-11 02:04:17

标签: c# events

当我的进程退出时,我想要一个小函数,但是,在关闭时(通过红色退出按钮),函数将不会执行。

我的代码如下:

namespace Client
{
    class Program
    {
        static void Main(string[] args)
        {
            var callback = new InstanceContext(new ClientCallback());
            var client = new MyServiceClient(callback);
            client.Open();
            client.Register();
            AppDomain.CurrentDomain.ProcessExit += (sender, EventArgs) =>
            {
                client.checkOut();
            };
            Console.WriteLine("Press a key to exit");
            Console.ReadKey();
            client.checkOut();
            client.Close();
        }
    }
}

1 个答案:

答案 0 :(得分:0)

float:left;

paper-ripple doc