que tienen una funciónTema Control.Invoke
public void ShowAllFly()
{
cbFly.Items.Clear();
cbFly.Items.Add("Uçuş Seçiniz...");
dsFlyTableAdapters.tblFlyTableAdapter _t=new KTHY.dsFlyTableAdapters.tblFlyTableAdapter();
dsFly _mds = new dsFly();
_mds.EnforceConstraints = false;
dsFly.tblFlyDataTable _m = _mds.tblFly;
_t.Fill(_m);
foreach (DataRow _row in _m.Rows)
{
cbFly.Items.Add(_row["FlyID"].ToString()+"-"+_row["FlyName"].ToString() + "-" + _row["FlyDirection"].ToString() + "-" + _row["FlyDateTime"].ToString());
}
_Thread.Abort();
timer1.Enabled = false;
WaitPanel.Visible = false;
}
En Form_Load función como ésta;
{
_Thread = new System.Threading.Thread(new System.Threading.ThreadStart(ShowAllFly));
_Thread.Start();
_Thread.Priority = System.Threading.ThreadPriority.Normal;
}
Pero cuando lo ejecuto;
en función ShowAllFly
cbFly.Items.Clear(); ---- HERE Gives ERROR LIKE Control.Invoke must be used to interact with controls created on a separate thread.
¿Cuál es el problema?
Buena solución; byt Yo recomendaría usar 'Action' desde el framework en lugar de rodar (y mantener) el suyo. –
Sí ... esta es más o menos la forma estándar de hacer esto. La razón por la que esto es necesario es que textBox1.Text solo se puede cambiar en el subproceso en el que se creó el cuadro de texto. Invocar es el proceso utilizado para volver a ese subproceso. –
@Fredrik: Tiene razón, pero este ejemplo se ve con más frecuencia, en gran parte porque ha durado más tiempo. Cualquiera de los métodos funcionará. –