I thank you for the suggestions. Thanks to them I found a solution that solves the problem, even if the user types very fast.
private void ReadManageAndWriteLine()
{
// open file with StreamReader
// for every line in the file, read it and do what you need to do
// then save the result in String outpuLine
int cp = GetCaretPosition();
txtBox.AppendText(outputLine + new string[] { Environment.NewLine });
SetCaretPosition(cp);
// go to the next line
}
private int GetCaretPosition()
{
int s = txtBox.SelectionStart;
return s;
}
private void SetCaretPosition(int cp)
{
txtBox.Select(cp, 0);
txtBox.Focus();
txtBox.ScrollToCaret();
}
Again, thank you so much, problem solved.