【问题标题】:Using BackgroundWorker or Threading for high performance使用 BackgroundWorker 或 Threading 以获得高性能
【发布时间】:2009-02-24 13:33:28
【问题描述】:

如何在我的代码中使用 BackgroundWorker 或 Threading。我更新 TreeView (Winforms) 并调用 WCF 服务。

请有任何建议。亲切的问候。

提前致谢

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

【问题讨论】:

  • 拜托,格式化你的代码,这很痛苦XD
  • 同意;缩进是你的朋友。
  • 我相信这里有一个代码标签只是为了代码。

标签: .net winforms multithreading backgroundworker


【解决方案1】:

使用 BackgroundWorker 或 one 线程不会使您的应用程序运行得更快,而只会阻止您的应用程序不响应。

如果您只需要一个线程,只需使用 BackgroundWorker,这就是它的意义所在。

如果在这种精确情况下,您的 listaFichero 变量可以拆分为更小的列表并并行处理,客户端之间的带宽并且服务器不是瓶颈,并且你的服务器支持并行进程,那么你可以创建多个线程。

【讨论】:

    【解决方案2】:

    说实话,只要你做得好,这并不重要。

    使用后台工作人员更容易正确完成,所以我建议使用它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-21
      • 1970-01-01
      • 2013-05-07
      • 2017-12-26
      • 2014-07-22
      • 1970-01-01
      • 2023-04-03
      • 2010-09-18
      相关资源
      最近更新 更多