【发布时间】:2011-01-14 14:34:06
【问题描述】:
我需要删除一个文件。有时,文件可能被锁定,在这种情况下,我想解锁并删除它。
到目前为止,我在研究中遇到了两种可能性。
System.IO.FileStream.Unlock
和
//unlock file
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern bool UnlockFile(IntPtr handle, int offsetLow, int offsetHi);`
这两种方法中的任何一种都有效吗?如果是这样,您能否提供一个样本,因为我还没有让其中任何一个工作。或者,还有其他更好的方法吗?
【问题讨论】: