开发者

Handling cleaning up on process termination

Am curious.. whether can i handle the cleaning up of an object. If i kill my application from Task Manager.

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.TaskManagerClosing)
            {
                e.Cancel = true;
                MessageBox.Show("Application being shutd开发者_运维技巧own from Task Manager","Caution",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            do{}while(true);
        }
    }

This method works if i end my application from the TASK MANAGER. But i want to know whether a similar handling is possible if i end my application by killing the process under which my application is running

Regards


You can't. Your process can't get any notifications when it's killed, because that would defeat the purpose of having forced process termination (as opposed to asking it to terminate). The OS releases most resources for you, so you shouldn't have any resources that need manual cleanup - what if the computer BSODs or I pull out the power cord?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜