0

我正在使用文件流和流写入器在文件上写一个小文本,它给了我 CA2202 警告

    public void WritePIDToFile()
    {
        FileStream fh = null;
        try
        {
            fh = new FileStream(HIMSHelper.ApplicationDirectory + "PID", FileMode.Open, FileAccess.ReadWrite, FileShare.Read);
            using (var sr = new StreamWriter(fh))
            {
                sr.Write(PID);
            }
        }
        finally
        {
            if (fh != null)
            {
                fh.Dispose();//I got CA2202 here
            }
        }
    }

我已经在这里尝试了解决方案CA2202: Do not dispose objects multiple times

你能给我一些建议吗?请。

谢谢

4

0 回答 0