📜  检查文件锁c#代码示例

📅  最后修改于: 2022-03-11 14:48:55.530000             🧑  作者: Mango

代码示例1
public bool IsFileLocked(string filePath)
{
    try
    {
        using (File.Open(filePath, FileMode.Open)){}
    }
    catch (IOException e)
    {
        var errorCode = Marshal.GetHRForException(e) & ((1 << 16) - 1);
        return errorCode == 32 || errorCode == 33;
    }
    return false;
}