clutten
June 22nd, 2004, 04:30 AM
I have a problem with the richtextbox. I'd like to read a logfile, then reverse it. This did not seem to be possible with LoadFile so I read the file into an arraylist and outputs it to the richtextbox with AppendText. With this solution it will also be quite easy to add output filters.
The problem is that there seems to be problems with number of lines the richtextbox can hold. If I output 2000 lines it takes approx. 5s before it's done, 10000 lines I waited about 1 minute and it was still not finished. The logfiles will contain much more than 10000 lines so this is a big problem. Using LoadFile it takes no time at all. So something's very wrong with my solution, anyone that can hint to me what's wrong, and maybe suggest a better approach to this.
Since all files starts with the date I added a check that they e´start with 2004 otherwise I had >18000 lines in a logfile with 15000 lines. This seems to be me as one possible problem is that the logfile contains some "forbidden" characters that richtextbox cannot handle. Still LoadFile loads the file without problems.
private void button1_Click(object sender, System.EventArgs e)
{
StreamReader sr = new StreamReader("c:\\logfile.txt");
//StreamReader sr = File.OpenText("c:\\logfile.txt");
string input = null;
//Should read from the bottom, doesn't seem to work with LoadFile...
//richTextBox1.LoadFile("c:\\logfile.txt",RichTextBoxStreamType.PlainText);
ArrayList myList = new ArrayList();
int linecnt = 0;
while ((input = sr.ReadLine()) != null)
{
if ( input.StartsWith("2"))
{
myList.Add(input);
//linecnt++;
}
}
sr.Close();
myList.TrimToSize();
myList.Reverse();
richTextBox1.Clear();
richTextBox1.Enabled = false;
int q = myList.Count;
//richTextBox1.Text = myList.Count.ToString() + "\t" + linecnt.ToString() + "\n";
for (int i=0;i < myList.Count ;i++)
{
richTextBox1.AppendText(myList[i].ToString() + "\n");
}
richTextBox1.Update();
richTextBox1.Enabled = true;
}
The problem is that there seems to be problems with number of lines the richtextbox can hold. If I output 2000 lines it takes approx. 5s before it's done, 10000 lines I waited about 1 minute and it was still not finished. The logfiles will contain much more than 10000 lines so this is a big problem. Using LoadFile it takes no time at all. So something's very wrong with my solution, anyone that can hint to me what's wrong, and maybe suggest a better approach to this.
Since all files starts with the date I added a check that they e´start with 2004 otherwise I had >18000 lines in a logfile with 15000 lines. This seems to be me as one possible problem is that the logfile contains some "forbidden" characters that richtextbox cannot handle. Still LoadFile loads the file without problems.
private void button1_Click(object sender, System.EventArgs e)
{
StreamReader sr = new StreamReader("c:\\logfile.txt");
//StreamReader sr = File.OpenText("c:\\logfile.txt");
string input = null;
//Should read from the bottom, doesn't seem to work with LoadFile...
//richTextBox1.LoadFile("c:\\logfile.txt",RichTextBoxStreamType.PlainText);
ArrayList myList = new ArrayList();
int linecnt = 0;
while ((input = sr.ReadLine()) != null)
{
if ( input.StartsWith("2"))
{
myList.Add(input);
//linecnt++;
}
}
sr.Close();
myList.TrimToSize();
myList.Reverse();
richTextBox1.Clear();
richTextBox1.Enabled = false;
int q = myList.Count;
//richTextBox1.Text = myList.Count.ToString() + "\t" + linecnt.ToString() + "\n";
for (int i=0;i < myList.Count ;i++)
{
richTextBox1.AppendText(myList[i].ToString() + "\n");
}
richTextBox1.Update();
richTextBox1.Enabled = true;
}