当我的进程退出时,我想要一个小函数,但是,在关闭时(通过红色退出按钮),函数将不会执行。
我的代码如下:
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();
}
}
}