InvokeRequired

Ya se que cuando queremos actualizar un formulario o control desde un thread distinto al que creo el control hay que usar el método Invoke o BeginInvoke pasandole un delegado a ejecutar.

Para no tener que definir el delegado podemos usar los metodos anónimos.


if( this.InvokeRequired )
{
this.Invoke( (System.Threading.ParameterizedThreadStart)delegate( object o )
{ UpdateProgressBar( current ); } , current );
}


o este si no necesitamos pasar parámetros


if( InvokeRequired )
{
this.Invoke( (MethodInvoker)delegate() { StopTest(); } );
}

No hay comentarios: