How do I automatically delete tempfiles in c#?

后端 未结 9 1672
旧巷少年郎
旧巷少年郎 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:56

    Its nice to see that you want to be responsible, but if the files aren't huge (>50MB) you would be in line with everyone (MS included) in leaving them in the temp directory. Disk space is abundant.

    As csl posted, the GetTempPath is the way to go. Users who are short on space will be able to run disk cleanup and your files (along with everyone else's) will be cleaned up.

提交回复
热议问题