BackgroundWorker_DoWork causing UI to be unresponsive?

百般思念 提交于 2019-12-11 07:21:44

问题


I am using a backgroundworker to fill a bunch of datasets using tableadapter.fill(). For some reason they are causing the UI to be unresponsive. How is this even possible? I'm not reporting any information back to the UI with it...it's just supposed to run in the background, no progressbar.

Me.spOpportunityTableAdapter.Fill(Me.DsBdPipeline.spOpportunity, CType(ActiveStatus, Integer))
Me.ClientTableAdapter.Fill(Me.DsBdPipeline.Client)
Me.ClientTypeTableAdapter.Fill(Me.DsBdPipeline.ClientType)
Me.ClientPriorityTableAdapter.Fill(Me.DsBdPipeline.ClientPriority)
Me.OpportunityStatusTableAdapter.Fill(Me.DsBdPipeline.OpportunityStatus)
Me.MarketSegmentTableAdapter.Fill(Me.DsBdPipeline.MarketSegment)
Me.ProcurementTypeTableAdapter.Fill(Me.DsBdPipeline.ProcurementType)
Me.BusDevProjectTableAdapter.Fill(Me.DsBdPipeline.BusDevProject)
Me.ProjectTableAdapter.Fill(Me.DsBdPipeline.Project)
Me.StateTableAdapter.Fill(Me.DsBdPipeline.State)
Me.OrgMapTableAdapter.Fill(Me.DsBdPipeline.OrgMap)
Me.EmployeeTableAdapter.Fill(Me.DsBdPipeline.Employee)
Me.ClientServiceManagerViewTableAdapter.Fill(Me.DsBdPipeline.ClientServiceManagerView)

回答1:


Honestly I don't know the why's and wherefores of why this was having trouble for some users and not others, but here is what fixed the problem.

I traced it to the TableAdapter.Fill methods executing in the backgroundworker DoWork method. It made no sense to me that something executing on a background thread, and which was not updating the UI with it's progress, would cause the UI to be unresponsive. So I figured it must be what the TableAdapter is filling being bound to a UI component and causing problems (only God knows why).

So I took all the design-time databinding off the controls. I reordered things so that in the backgroundworker thread, the TableAdapter's fill. In the RunWorkerCompleted method, I bind the controls to the BindingSource.

And voila, problem solved.



来源:https://stackoverflow.com/questions/10099025/backgroundworker-dowork-causing-ui-to-be-unresponsive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!