views:

54

answers:

2

Is there an Easy way to implement FIFO in RichTextBox control?

Actually i have a testing tool that produce more than 1000 lines within a minute that is why i want to limit the total number lines and when a new line adds in the control the Last line should be removed.

A: 

Today I came across Infinite-Scroll design pattern. I think it might help.

OLD ANSWER:

List<string> lines = new List<string>();

int max = 2;

int n = 0;

private void button1_Click(object sender, EventArgs e)
{
    lines.Insert(0,n.ToString());

    richTextBox1.Text = string.Join("\n", lines.Take(max).ToArray<string>());

    n++;
}

This is very simple FIFO. Also in List<string> l you will have log at all the times :)

TheMachineCharmer
:( This is not that simple there are many formating scenarios i have to make them on each entry and it will be performance factor please consider the max value = 10,000
Mubashar Ahmad
it slows down the processing as there are number of threads writing logs and you know UI object can only be accessed from UI Thread :(
Mubashar Ahmad
A: 

Not an answer to your question but do you read all of the 1000 messages in a minute? Is there a way (or already is) to log only messages from a 'level'. quote from java:

* SEVERE (highest value)
* WARNING
* INFO
* CONFIG
* FINE
* FINER
* FINEST (lowest value)

For example: normally you would have: message 1(debug) and message 2(SEVERE ) Prefix each line according to their level:

  • 1:message 1
  • 7:message 2

Now you can modify your testing tool to log only a certain level. 7 logs all, 1 logs only 1 etc. Result is less unnecessary logging and readable output (for example 2 messages should arise right after each other, but because of threading there are 20 messages between in the logging...)

PoweRoy