This is my code but label1 runs first before label2 does? What I wanted is to run label1 and label2 at the same time on their respective threads. I've use threads by the way but it cannot access controls except in its own thread where it is created. So in this code, when I create instance such as: Slave s1 = new Slave(label1); Slave s2 = new Slave(label2);
it will automatically start moving the two labels, but its not.
public class Slave
{
private Label l;
private BackgroundWorker bw;
public Slave(Label l)
{
this.l = l;
bw = new BackgroundWorker();
bw.WorkerReportsProgress = true;
bw.DoWork+=new DoWorkEventHandler(worknow);
bw.ProgressChanged += new ProgressChangedEventHandler(update);
bw.RunWorkerAsync();
}
private void worknow(object sender, DoWorkEventArgs e)
{
BackgroundWorker b = sender as BackgroundWorker;
b.ReportProgress(1);
}
private void update(object sender, ProgressChangedEventArgs e)
{
for(int x=0; x<20;x++)
{
l.Top += 10;
System.Threading.Thread.Sleep(100);
}
}
}