From: Udi on
Hi,
I have two processes, one writres a text file and the other reads it.
I'm looking for a way to pend the reader when it reaches to the end of
the file, for as long as the writer holds the file open.
i.e. if the reader reaches EOF, and then the writer adds a new row,
i'd like the reader to be able to read the new rows until the writer
releases the file.

Is there an easy way to implement this?
Thanks,
Udi
From: RayLopez99 on
On May 10, 10:15 am, Udi <udibensen...(a)gmail.com> wrote:
> Hi,
> I have two processes, one writres a text file and the other reads it.
> I'm looking for a way to pend the reader when it reaches to the end of
> the file, for as long as the writer holds the file open.
> i.e. if the reader reaches EOF, and then the writer adds a new row,
> i'd like the reader to be able to read the new rows until the writer
> releases the file.
>
> Is there an easy way to implement this?
> Thanks,
> Udi

Not sure what you mean--you mean 'read only'? I think that's doable
even if you have several processes reading the same stream. Try it
and see.

RL
From: Arne Vajhøj on
On 10-05-2010 10:15, Udi wrote:
> I have two processes, one writres a text file and the other reads it.
> I'm looking for a way to pend the reader when it reaches to the end of
> the file, for as long as the writer holds the file open.
> i.e. if the reader reaches EOF, and then the writer adds a new row,
> i'd like the reader to be able to read the new rows until the writer
> releases the file.

If the file meta data is kept uptodate, then you may be able to
do it by maintaining position and compare that with file length.

In general that write-file-read-file approach is error-prone. Wny
not use named pipe/TCP socket instead? Much easier!

Arne
From: Bert Hyman on
In
news:552afb32-af94-4edf-9c52-0cd21b03d3cf(a)g21g2000yqk.googlegroups.com
Udi <udibensenior(a)gmail.com> wrote:

> i'd like the reader to be able to read the new rows until the writer
> releases the file.

You could try re-opening the file with OF_SHARE_EXCLUSIVE or
OF_SHARE_DENY_WRITE. I'm sorry that I can't name the specific C#
class/method for doing that, but it must be in there somewhere :-)

So long as any other process has the file open for writing, your attempt
will fail. Once you're able to open the file in either of those modes,
you'll know that the writing process has closed the file.

That would involve closing and opening the file each time you check, but
that might not be too much trouble.

--
Bert Hyman St. Paul, MN bert(a)iphouse.com
From: Arne Vajhøj on
On 10-05-2010 18:44, Bert Hyman wrote:
> In
> news:552afb32-af94-4edf-9c52-0cd21b03d3cf(a)g21g2000yqk.googlegroups.com
> Udi<udibensenior(a)gmail.com> wrote:
>> i'd like the reader to be able to read the new rows until the writer
>> releases the file.
>
> You could try re-opening the file with OF_SHARE_EXCLUSIVE or
> OF_SHARE_DENY_WRITE. I'm sorry that I can't name the specific C#
> class/method for doing that, but it must be in there somewhere :-)

The FileStream class has constructors with all the
options:
http://msdn.microsoft.com/en-us/library/5h0z48dh.aspx

Arne