I wrote this code in C# under visual studio 2013, I want to see the value on textbox1,textbox2 and textbox3 will be updating in real time, but it did not. it only display the last value when execution is done.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Threading; namespace uiElementUpdateMultithread { public partial class Form1 : Form { public Form1() { InitializeComponent(); } Thread thrtb1; Thread thrtb2; Thread thrtb3; private void numericUpDown1_ValueChanged(object sender, EventArgs e) { } private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { thrtb1 = new Thread(tb1ControlsUpdate); thrtb1.Start(); thrtb2 = new Thread(tb2ControlsUpdate); thrtb2.Start(); } public delegate void deltb1(); public delegate void deltb2(); public void updateTextBox1() { for (int i = 0; i < 10; i++) { textBox1.Text += i.ToString(); Thread.Sleep(100); } textBox1.Text += "\r\n"; } public void updateTextBox2() { for (int i = 0; i < 10; i++) { textBox2.Text += i.ToString(); Thread.Sleep(50); } textBox2.Text += "\r\n"; } public void updateTextBox3() { for (int i = 0; i < 10; i++) { textBox3.Text += i.ToString(); Thread.Sleep(10); } } public void tb1ControlsUpdate() { for (int i = 0; i < 10; i++) { textBox1.Invoke(new deltb1(updateTextBox1)); } } public void tb2ControlsUpdate() { for (int i = 0; i < 10; i++) { textBox2.Invoke(new deltb2(updateTextBox2)); } } } }