应为是两个程序一个写,一个读 不想通过中间什么东西,判断下是否在写,在写的话不读,读的话不写!谢谢!

解决方案 »

  1.   


    [DllImport("kernel32.dll", SetLastError=true)] static extern int LockFile ( int hFile, int dwFileOffsetLow, int dwFileOffsetHigh, int nNumberOfBytesToLockLow, int nNumberOfBytesToLockHigh);
    [DllImport("kernel32.dll", SetLastError=true)] static extern int UnlockFile ( int hFile, int dwFileOffsetLow, int dwFileOffsetHigh, int nNumberOfBytesToUnlockLow, int nNumberOfBytesToUnlockHigh) ;
      

  2.   

    文件不大,就一次性读入内存.
    如果很大的读lock
      

  3.   

    创建FileStream时要设置参数。写的程序创建时FileShare设为不共享,
    读的程序,创建时捕捉异常即可。