Reading a Text File in C# as it is being written to

B

BillGatesFan

A file is being written to by another process. Is there a way I can
open up the file in c# and display the contents in a textbox as the
other application is writing to it? I have seen applications do this I
just can't figure out how to write it in c#.

Code would be greatly appreciated. Thanks
 
P

Peter Duniho

A file is being written to by another process. Is there a way I can
open up the file in c# and display the contents in a textbox as the
other application is writing to it? I have seen applications do this I
just can't figure out how to write it in c#.

Only if the writing and reading applications are cooperating. The key
would be to make sure that the file is opened by both applications with
appropriate sharing and modes, and to periodically attempt to read from
the file (every second or so, for example...don't do it too often,
otherwise you'll kill performance).

If you don't have control over the writing application, chances are that
it opens the file for writing with an exclusive access mode and you won't
be able to do what you want.

Pete
 
B

BillGatesFan

Only if the writing and reading applications are cooperating. The key
would be to make sure that the file is opened by both applications with
appropriate sharing and modes, and to periodically attempt to read from
the file (every second or so, for example...don't do it too often,
otherwise you'll kill performance).

If you don't have control over the writing application, chances are that
it opens the file for writing with an exclusive access mode and you won't
be able to do what you want.

Pete

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top