0

Heres the for loop I'm using

           for(int i = 0; i < fullText[buttPress].Length; i++) 
            {
                TalkBox.Text += fullText[buttPress][i];
                System.Threading.Thread.Sleep(10);
            }

the fullText variable is a string array and I'm taking each character and adding it to the text box and making it sleep but it isn't working, it just waits and then puts out the entire string.

  • It's because the UI thread is blocked by your for loop until it returns, so it's not doing any drawing/event processing. You can cheat by adding an Application.DoEvents() in your loop (assuming this is winforms) or you can do it right with an async void method and an await Task.Delay(10); in place of your sleep. – adv12 Apr 07 '22 at 14:53
  • The answers on the duplicate are all pretty bad. Best approach is probably async/await. – adv12 Apr 07 '22 at 14:56

0 Answers0