update UI in Task using TaskScheduler.FromCurrentSynchronizationContext
问题 I want to add some text to list box using Task and I simply use a button and place in click event this code: TaskScheduler uiScheduler = TaskScheduler.FromCurrentSynchronizationContext(); Task.Factory.StartNew(() => { for (int i = 0; i < 10; i++) { listBox1.Items.Add("Number cities in problem = " + i.ToString()); System.Threading.Thread.Sleep(1000); } }, CancellationToken.None, TaskCreationOptions.None, uiScheduler); but it does not work and UI locked until the end of the for loop. Where is