yraen
April 14th, 2008, 07:12 PM
What I'm trying to do is create an app that will open a text file (that is currently being appended to by another program), read the newest lines, pull information from those lines into various variables, and then wait until more lines are added.
I've got the opening of the file and the variable comparisons working fine... what I can't get is how to make it read only the lines from the time my app is started until I close it and pull the information from those lines.
I'm using a StreamReader... and my code (plus attempted codes, yes it's ugly at the moment) looks like:
//while ((strLine = sr.ReadLine()) != null)
//buffersize = 4096;
//char[] buffer = new char[buffersize];
//while (1 != 2)
//{
fs = new FileStream(strPath2, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
sr = new StreamReader(fs);
//sr.BaseStream.Seek(intLength1, SeekOrigin.Current);
intLength2 = Convert.ToInt32(sr.BaseStream.Length);
while (intLength2 > intLength1)
{
long intStore = Convert.ToInt64(intLength2 - intLength1);
buffersize = intLength2;
char[] buffer = new char[buffersize];
//sr.BaseStream.Seek(intStore, SeekOrigin.Begin);
//sr.BaseStream.Position = intLength1;
intLength1 = Convert.ToInt32(sr.BaseStream.Length);
sr.BaseStream.Seek(intStore, SeekOrigin.End);
strLine = Convert.ToString(sr.Read(buffer, intLength1, Convert.ToInt32(intStore)));
//sr.BaseStream.SetLength(Convert.ToInt64(intStore));
while ((strLine = sr.ReadLine()) != null)
//the rest of my code
Anyone have any tips on how to make this work?
I've got the opening of the file and the variable comparisons working fine... what I can't get is how to make it read only the lines from the time my app is started until I close it and pull the information from those lines.
I'm using a StreamReader... and my code (plus attempted codes, yes it's ugly at the moment) looks like:
//while ((strLine = sr.ReadLine()) != null)
//buffersize = 4096;
//char[] buffer = new char[buffersize];
//while (1 != 2)
//{
fs = new FileStream(strPath2, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
sr = new StreamReader(fs);
//sr.BaseStream.Seek(intLength1, SeekOrigin.Current);
intLength2 = Convert.ToInt32(sr.BaseStream.Length);
while (intLength2 > intLength1)
{
long intStore = Convert.ToInt64(intLength2 - intLength1);
buffersize = intLength2;
char[] buffer = new char[buffersize];
//sr.BaseStream.Seek(intStore, SeekOrigin.Begin);
//sr.BaseStream.Position = intLength1;
intLength1 = Convert.ToInt32(sr.BaseStream.Length);
sr.BaseStream.Seek(intStore, SeekOrigin.End);
strLine = Convert.ToString(sr.Read(buffer, intLength1, Convert.ToInt32(intStore)));
//sr.BaseStream.SetLength(Convert.ToInt64(intStore));
while ((strLine = sr.ReadLine()) != null)
//the rest of my code
Anyone have any tips on how to make this work?