You could use the System.Threading class to call: Thread.Sleep(1000);
once per loop iteration.
More information on the System.Threading class at MSDN
EDIT:
As mentioned below, using Thread.Sleep causes the UI to lock up during the Sleep method. As an alternative, you may like to try the BackgroundWorker class.
The following snippet assumes you want to trigger your code above from a button click (it was unclear from the question whether this is actually the case or not).
private void startAsyncButton_Click(object sender, EventArgs e)
{
if(backgroundWorkerA.IsBusy != true)
{
//start the Async Thread
backgroundWorkerA.RunWorkerAsync();
}
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
StreamReader file = new StreamReader(@"C:\Users\User\Documents\Files.txt");
while ((line = file.ReadLine()) != null)
{
richTextBox1.Text += Environment.NewLine + "Copying: " + line;
counter++;
Thread.Sleep(1000);
}
}
Here you are simply creating a worker thread to do the (relatively) time-consuming task without tying up your GUI.