//Las operaciones entre subprocesos no son válidas =======NG
private void button1_Click(object sender, EventArgs e)
{ Thread t = new Thread(RunWorkerThread); t.Start(); }
void RunWorkerThread(Objeto o)
{ SetBackground(null); }
void SetBackground(Object o)
{ //this.BackColor = Brushes.Red;
this.BackColor = System.Drawing.SystemColors.ButtonFace;
}
//Las operaciones entre hilos son válidas =======OK
private void button2_Click(object sender, EventArgs e)
{ Thread t = new Thread(RunWorkerThread11); t.Start(SynchronizationContext.Current);//Sincronización actual entrante Contexto } void RunWorkerThread11(Object o) { //Usar el contexto entrante para enviar el mensaje al subproceso original SynchronizationContext sc = o as SynchronizationContext; sc.Post(SetBackground11, null); }
void SetBackground11(Objeto o)
{ this. BackColor = System.Drawing.SystemColors.ActiveCaptionText; }