try
                {
                    fs = new FileStream(Program.VIDEOPATH + "progress.log", FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
                    byte[] bts = ASCIIEncoding.ASCII.GetBytes(DateTime.Now.Ticks.ToString());                    fs.Write(bts, 0, bts.Length);
                    fs.Flush();                }
                catch (Exception e)
                {
                    LoggerNS.Logger.writeToLog("Write process exception:"+e.Message);
                }
                finally
                {
                    fs.Close();
                   // fs.Dispose();
                }总是出现错误The process cannot acccess the file 'c:\VideoFolder\progress.log' because it is being used by another process.
不知道是哪里的问题,又没有开别的程序,而且这是个单线程的程序,而且又用了try catch。为什么这么奇怪呢?

解决方案 »

  1.   

    请确保progress.log这个文件没有在使用中.是不是其他软件打开了progress.log?
      

  2.   

    你在try前面没有个File.Crteate()函数?如果有的话,当图片文件不存在的时候 会报这个错误。
      

  3.   

    补充一下,这段代码是在一个while loop 中,每个循坏停1秒。不是一开始就报错,报错是随机的,有时工作了几十个小时后报错,有时几小时报错。一报错整个程序终止,但是我用了try catch啊。
      

  4.   

    简单做法,把"progress.log"换成"test.txt",试试
      

  5.   

    这个问题也太奇怪了,是不是微软的bug?
      

  6.   

    建议 seelp 一下 还有 你try catch 的话  catch不要去抓异常 就好了 
      

  7.   

    FileMode.Create 指如果存在就覆盖
    还有个前提是文件不是隐藏的,是不是系统有什么问题把progress.log设置为隐藏