Language used: C#
Theory: I want to create a file with the flag FileOptions.DeleteOnClose in a temporary folder. The file is successfully created and I write dato onto it, the next step is to launch the application associated with the file Process.Start(...) and allow the user to inspect the document, finally I close my handle and as soon as other process close the handle to the temporary file, the file is deleted by operating system.
My problem is that other processes cannot open the file, even for reading, despite if I add FileShare.ReadWrite | FileShare.Delete to the sharing mode.
Any suggestions?
解决方案
The other processes need to specify FileShare.Delete when they open the DeleteOnClose file
From the MSDN CreateFile docs:
"FILE_FLAG_DELETE_ON_CLOSE... Subsequent open requests for the file fail, unless the FILE_SHARE_DELETE share mode is specified."
使用语言:C#
理论:
我想创建一个临时文件夹的标志FileOptions.DeleteOnClose的文件。
中的文件创建成功,我写上拿督它,下一步是启动与文件的Process.Start(...)相关的应用程序,并允许用户检查文档,最后我关闭句柄并尽快其他程序关闭句柄到临时文件,该文件是由操作系统删除。
我的问题是其他进程无法打开文件,甚至读书,尽管如果我添加FileShare.ReadWrite | FileShare.Delete到共享模式。
有什么建议?
解决方案
其他工艺需要指定 FileShare.Delete 当他们打开 DeleteOnClose 文件
从 MSDN的CreateFile 文档:
FILE_FLAG_DELETE_ON_CLOSE ...该文件的后续打开请求失败,除非 FILE_SHARE_DELETE 指定共享模式。
块引用>