How do I automatically delete tempfiles in c#?

后端 未结 9 1698
旧巷少年郎
旧巷少年郎 2020-12-04 11:35

What are a good way to ensure that a tempfile is deleted if my application closes or crashes? Ideally I would like to obtain a tempfile, use it and then forget about it.

9条回答
  •  情书的邮戳
    2020-12-04 11:50

    If you're building a Windows Forms Application, you can use this code:

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            File.Delete("temp.data");
        }
    

提交回复
热议问题