Re: Simultaneously Write to and Read from the same file
- From: "Chris Dunaway" <dunawayc@xxxxxxxxx>
- Date: 4 Oct 2005 07:35:04 -0700
cnu wrote:
> this.m_fsLog = new FileStream(strTodaysLogFile, System.IO.FileMode.Append,
> System.IO.FileAccess.Write, System.IO.FileShare.Read);
This part is OK. You are opening the file for writing
(FileAccess.Write) and you grant other processes the right to Read
(FileShare.Read).
> System.IO.FileStream fs = new FileStream(this.m_strCurrentFileName,
> System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);
This is where the problem is. You open the file for reading
(FileAccess.Read) but then you try to restrict other processes by
saying they can only Read (FileShare.Read). FileShare.Read means:
"Only let other processes Read from this file". Since you have already
opened the file for writing elsewhere, this is causing a conflict. You
should specify FileShare.ReadWrite when opening the file for reading.
>
> As you see, when I open the file for writing, I'm granting FileShare.Read,
> which means other processes can open the file for reading. But when I try to
Right, but when you open it for reading, you specified FileShare.Read
which means other processes cannot write. Since your first process is
already writing, it can't open in this mode.
.
- Prev by Date: Re: Free Copies of Visual Studio 2005 and SQL Server 2005 at Launch Tour
- Next by Date: Re: Combobox issue
- Previous by thread: Pass parameters to Oracle stored procedure with cursor
- Next by thread: IS THIS POSSIBLE: Creating a virtual file
- Index(es):
Relevant Pages
|