I have a button and a label on my UI. When i clicks on the button i want to show “In Progress” on the label until the for loop finished and then again the same label should show the result of the collection.
private void button1_Click(object sender, RoutedEventArgs e)
{
label1.Content = "In progress..";
List<string> intList = new List<string>();
for (long i = 0; i <= 50000000; i++)
{
intList.Add("Test");
}
label1.Content = intList.ToString();
}
You’ll need to farm the work out to a background thread, otherwise your loop continues on the UI thread hence you see no “progress”.
You can use a BackgroundWorker or a Task to accomplish this: