问题
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