I have a windows.form.userControl class, and at runtime I want to add some reference tags dynamically. When I apply this piece of code inside the Load method, it works fine.
for (int i = 0; i < 10; i++)
{
linkLabel = new System.Windows.Forms.LinkLabel();
linkLabel.Name = i.ToString();
linkLabel.Text = i.ToString();
linkLabel.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(linkLabel_LinkClicked);
this.Controls.Add(linkLabel);
linkLabel.Top = top;
top += 30;
}
But when I move this piece of code inside the backgroudworker doWork method , it will give an invalid statement related to the cross-thread problem on this line: - . Controls.Add (LinkLabel);
How to make this a safe thread? I am new to C # and I am using C # 4.0 using VS 2010. Thanks in advance.
source
share