Here is my final code:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
for (int i = 1; i <= 1000; i++)
{
Label lbl = new Label();
lbl.Name = "lbl" + i;
lbl.Text = i.ToString();
lbl.BorderStyle = BorderStyle.FixedSingle;
lbl.AutoSize = true;
lbl.BackColor = Color.LightSalmon;
lbl.ForeColor = Color.DarkViolet;
Thread.Sleep(50);
backgroundWorker1.ReportProgress(i,lbl);
}
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
int percentage = ((e.ProgressPercentage * 100) / 1000);
progressBar1.Value = percentage;
Label lbl =(Label) e.UserState;
flowLayoutPanel1.SuspendLayout();
flowLayoutPanel1.Controls.Add(lbl);
flowLayoutPanel1.ResumeLayout();
}
I changed the flowLayoutPanel1 update method, it updated on every Label creation on worker thread and also sending worker thread to sleep for 50 milliseconds(in the meantime the UI can update properly)..
and thanks to @F-ES Sitecore for the Idea...