Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

C# – Refresh WPF RichTextBox during a loop

I’m new learner in C# and i have a simple problem.

I do classic loop of 15 iterations with a Threat.Sleep of 3 secondes in each ones and inside this loop at each iteration i’m addind text to my RichTextBox.
BUT the text only appear at the end of the 15 iterations of 3 secondes ! 🙁

I want the text to be added at each iteration in the loop 🙂 Is there a way to do that ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thank you for helping 🙂

AMIGA RULEZ

>Solution :

I tested this code and it worked.
When i press the button, the RTB adds the word "hello" each 3 seconds.

    private async void button1_Click(object sender, EventArgs e)
    {
        for(int i=0; i<16; i++)
        {
            richTextBox1.Text += "hello";
            await Task.Delay(3000);
        }
    }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading