You cannot access controls exactly from the thread that they were created on: the UI thread.
You are trying to access them from your BackgroundWorker, which is a different thread entirely.
Either use the Invoke method to access them, or move the code into the UI thread via the BackgroundWorker.ReportProgress method.
"Sir, sorry for the missing info..
I tested this all methods loops with 30 (means Noq=30).
If I do it with 100 then it will be getting longer time(more then 4 min.) to execute ...
then the problem will arise .... :-(
How to solve this???"
A quick test gives me different results to you - but that is to be expected. I get around 300ms, increasing by 150ms odd each time I press the button and add another 30 buttons, so it's likely that your layout panel is setup different to mine.
However, have you considered what you are doing here? Each time you add a control, the layout panel has a whole pile of work to do...
So, try again, still with your Stopwatch code in there, and see what happens with a simple mod:
Stopwatch s1 = new Stopwatch();
s1.Start();
tableLayoutPanel1.SuspendLayout();
for (int i = 1; i <= Noq; i++)
{
Button lbl = new Button();
lbl.Text = i.ToString();
lbl.AutoSize = true;
lbl.AutoSizeMode = AutoSizeMode.GrowAndShrink;
lbl.Font = new Font("Comic Sans MS", 9, FontStyle.Bold);
lbl.BackColor = Color.AntiqueWhite;
lbl.Click += new EventHandler(lbl_Click);
tableLayoutPanel1.Controls.Add(lbl);
}
tableLayoutPanel1.ResumeLayout();
s1.Stop();
You should find your numbers drop immediately to a consistent, smaller, value because you are only causing the layout panel to recalculate the once.