Reading file every 1 second

  • Thread starter Thread starter Pujo Aji
  • Start date Start date
P

Pujo Aji

Hello,

I would like to read file during runtime(the other third party vendor
write the program and my program read it every second). I can't do it
until the third party vendor stop writing it. anyone can help?

Sincerely Yours,
Pujo
 
Hi,

FileStream constructor has a FileShare parameter.
I believe that setting it to "ReadWrite" allow you to
access read/write operation.
But there can be problem if "third party vendor" doesn't
allow to share that file.

HTH
Marcin
 
Hi,

I think the third party vendor give the access, since I can open using
notepad and see the difference every 1 second.
I use this code before:
string sLN;
try {
using (TextReader tr = new StreamReader(FN)) {
sLN = tr.ReadLine();
while (sLN != null) {
//show in console
sLN = tr.ReadLine();
}
tr.Close();
}
}
catch {
//give some info;
}

How can I use the FileStream, FileShare parameter?

Sincerely Yours,
Pujo Aji
 
Hi,

Use a FileStream and decorate it with a StreamReader:

FileStream fs = new FileStream( file , FileMode.Open, FileAccess.Read )
StreamReader reader = new StreamReader( fs)

it may solve your problem.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



Hi,

I think the third party vendor give the access, since I can open using
notepad and see the difference every 1 second.
I use this code before:
string sLN;
try {
using (TextReader tr = new StreamReader(FN)) {
sLN = tr.ReadLine();
while (sLN != null) {
//show in console
sLN = tr.ReadLine();
}
tr.Close();
}
}
catch {
//give some info;
}

How can I use the FileStream, FileShare parameter?

Sincerely Yours,
Pujo Aji
 
Hi,

I tried to implement your suggestion into my code:
string sLN;
try{
FileStream fs = new FileStream(File,FileMode.Open,FileAccess.Read);
StreamReader reader = new StreamReader(fs);
sLN = reader.ReadLine();
while (sLN != null) {
//write to console
sLN = reader.ReadLine();
}
}
catch{
//Information
}

It doesn't work, the result is the same.Am I missing something?

Pujo
 
Back
Top