How to Thread.Sleep in BeginInvoke
I tried to update a TextBox.Text to display from 1 to 10 with an internal of 1 second with the following code. I do not understand why the entire UI sleeps for 10 second before the text is updated to 10, as I though the Thread.Sleep(1000) should belong to a separate background thread created by Dispatcher.BeginInvoke . What is wrong with my code? Thread t1 = new Thread(new ThreadStart( delegate() { this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(delegate() { for (int i = 1; i < 11; i++) { mytxt1.Text = "Counter is: " + i.ToString(); Thread.Sleep(1000); } })); })); t1.Start();