How do I automatically delete tempfiles in c#?

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

    You could P/Invoke CreateFile and pass the FILE_FLAG_DELETE_ON_CLOSE flag. This tells Windows to delete the file once all handles are closed. See also: Win32 CreateFile docs.

提交回复
热议问题