Beispiel #1
0
        Stream OpenWrite(string name, bool buffered = false)
        {
            for (int i = 0; i < 10; i++)
            {
                try
                {
#if NETFX_CORE
                    Stream s = new OSFileStream(name, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
                    return(buffered ? new BufferedStream(s, BufferSize) : s);
#else
                    return(new FileStream(name, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None, buffered ? BufferSize : 4 * 1024));
#endif
                }
                catch
                {
#if NETFX_CORE
                    Sleep(100);
#else
                    Thread.Sleep(100);
#endif
                }
            }

            throw new IOException("Cannot aquire read lock");
        }
    Stream OpenWrite(string name, bool buffered = false)
    {
      for (int i = 0; i < 10; i++)
        try
        {
#if NETFX_CORE
          Stream s = new OSFileStream(name, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
          return buffered ? new BufferedStream(s, BufferSize) : s;
#else
          return new FileStream(name, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None, buffered ? BufferSize : 4 * 1024);
#endif
        }
        catch
        {
#if NETFX_CORE
          Sleep(100);
#else
          Thread.Sleep(100);
#endif
        }

      throw new IOException("Cannot aquire read lock");
    }