Ver Mensaje Individual
  #2 (permalink)  
Antiguo 27/09/2012, 12:04
Avatar de Dradi7
Dradi7
 
Fecha de Ingreso: junio-2008
Ubicación: Peru - Lima
Mensajes: 1.518
Antigüedad: 15 años, 11 meses
Puntos: 220
Respuesta: C#: Multithreading

En un tema de esto foro puse como puedes crear thread


Cita:
Iniciado por Dradi7 Ver Mensaje
Ejemplo como debes implementarlo

Código vb:
Ver original
  1. Dim Ts As ThreadStart
  2. Dim T As Thread
  3.  
  4. Delegate Sub cambiarColor(ByVal c As Color)
  5. Dim cc As cambiarColor
  6.  
  7. Private Sub Procesar()
  8.     Ts = New ThreadStart(AddressOf Aplicar_Filtro)
  9.     T = New Thread(Ts)
  10.     T.Start()
  11. End Sub
  12.  
  13. ' OJO CUANDO ESTES USANDO PROCESOS EN SEGUNDO PLANO Y QUIERE MANEJAR(REALIZAR CAMBIOS) OBJETOS QUE SE ENCUENTREN EN PRIMER PLANO DEBES USAR DELEGADOS
  14. Private Sub Aplicar_Filtro()
  15.     ' MOSTRAMOS MENSAJE ESTE MENSAJE NO NECESITA DELEGADO PORQUE NO DEPENDE DE PROCESOS EN PRIMER PLANO
  16.     msgbox("Mostrando Mensaje")
  17.     ' EN CAMBIO SI HAGO ESTO
  18.     txtAviso.Text = "Filtrando" ' ME DARA ERROR PORQUE ESTOY TRATANDO DE CAMBIAR ALGO QUE ESTA EN PRIMER PLANO, ENTONCES ACA USO LOS DELEGADOS
  19.    
  20.     ' USANDO DELEGADOS
  21.     bb = New cambiarColor(AddressOf cambiarColorBackground)
  22.     If txtAviso.InvokeRequired Then txtAviso.Invoke(bb, Color.Red)
  23. End Sub
  24.  
  25. private sub cambiarColorBackground(ByVal c As Color)
  26.     txtAviso.Color = c
  27. end sub

Este es un ejemplo basico de como vas a utilzarlo por cada control que vas a realizar cambios entonces debes usar delegados
__________________
La clave de todo triunfador es eliminar todas sus excusas y sus limitaciones