I have this weird problem with a class I implemented for reading files that are appended multiple time per second and are located in network shares. During the first iteration everything is fine and at the end of the reading I keep the last position in database. During the second pass however, the filestream does not "see" the actual size of the appended file but it remembers the previous size.
Could it be the fact that I am reading from network shares? Thank you in advance for your feedback.
public long? ReadFromFile(string Path, long lastposition, int ClusterId, Startup ST)
{
QuickFix.FieldMap QFM = new QuickFix.FieldMap();
FileStream fs =new FileStream(Path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite,1024,true);
StreamReader sr = new StreamReader(fs);
long CurrentPosition = lastposition;
sr.BaseStream.Seek(lastposition, SeekOrigin.Begin);
string line;
long i = 0;
while ((!sr.EndOfStream))
{
line = sr.ReadLine();
CurrentPosition = CurrentPosition + System.Text.ASCIIEncoding.ASCII.GetByteCount(line) + 1;
}
lastposition = CurrentPosition;
sr.Close();
sr.Dispose();
fs.Flush();
fs.Close();
fs.Dispose();
return lastposition;
}
The first pass is always successfull. The second pass does not go through the loop b/c the lastposition where I am moving the pointer remains the same even though the actual file has grown up.
UPDATE: The file is located in a solaris server.