Friday, April 8, 2011

Using BackgroundWorker or Threading for high performance

Hi all,

How can use BackgroundWorker or Threading for my code. I update TreeView (Winforms) and I call WCF service.

Any suggestions please. Kind regards.

Thanks in advance

AdministradorUILogging.TrazarDebug("PanelArbolFicheros. tslGuardarArbol_Click")
Dim listaFichero As New List(Of Fichero)

Windows.Forms.Cursor.Current = Cursors.WaitCursor

Me.TreeViewGB1.SuspendUpdate()

For Each nodo As NodoArbol In TreeViewGB1.Nodes

ProcesarNodo(nodo, listaFichero)

Next

Me.TreeViewGB1.ResumeUpdate()

' Cambiamos el cursor , tener en cuena si hacerlo asincrono '

Try

Using bfll As New ComunBfll()

bfll.AltaManualListaFicheros(listaFichero)

Mensajes.InformacionGuardada()

End Using

Catch ex As WCF.ServicioBase.Contrato.Excepciones.NoExisteOperacionException

Mensajes.AdvertenciaErrores("No existe la operación")

Catch ex As WCF.ServicioBase.Contrato.Excepciones.NoExisteExpedienteException

Mensajes.AdvertenciaErrores("No existe el expediente")

Catch ex As WCF.ServicioBase.Contrato.Excepciones.ConsistenciaException

Mensajes.AdvertenciaErrores("Inconsistencia detectada al superar el máximo permitido de ficheros para un tipo documental")

Catch ex As Exception

AdministradorUILogging.TrazarError(Me.[GetType]().FullName & " -> " & System.Reflection.MethodBase.GetCurrentMethod().Name & "." & ex.Message)

ExcepcionesIUUtil.ProcesarExcepcionPresentacion(ex, Me.Container)

End Try

InicializarArbol()

Windows.Forms.Cursor.Current = Cursors.Arrow
From stackoverflow
  • To be honest it doesn't matter as long as you do it properly.

    It easier to do properly with a background worker so i'd suggest doing it with that.

  • Using a BackgroundWorker or one thread will not make your application go faster, but will just prevent your application from not responding.

    If you only need one thread, just use a BackgroundWorker, that's what it's meant for.

    If in this precise case, your listaFichero variable can be splitted into smaller lists and processed in parallel, and the bandwidth between the client and the server is not a bottleneck, and your server supports parallel process, then you can create multiple threads.

0 comments:

Post a Comment