BackgroundWorker_DoWork导致用户界面无响应? [英] BackgroundWorker_DoWork causing UI to be unresponsive?

查看:907
本文介绍了BackgroundWorker_DoWork导致用户界面无响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是BackgroundWorker的使用tableadapter.fill填写一堆数据集()。出于某种原因,他们所造成的用户界面无响应。这是怎么可能?我没有报告任何信息反馈给它的用户界面......它只是应该在后台运行,没有任何进度。

  Me.spOpportunityTableAdapter.Fill(Me.DsBdPipeline.spOpportunity,CT​​YPE(ActiveStatus,整数))
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)
 

解决方案

老实说,我不知道为什么就是和为什么这是有问题的一些用户,而不是别人来龙去脉,但这里是解决了问题。

我跟踪它执行的BackgroundWorker的的DoWork 方法 TableAdapter.Fill 的方法。它没有任何意义,我认为执行的东西在后台线程,而这是没有更新的用户界面与它的进步,会导致用户界面停止响应。所以,我想那一定是什么TableAdapter的是填充被绑定到UI组件,造成的问题(只有上帝知道为什么)。

于是,我把所有的设计时数据绑定断控制。我重新排序的东西,以便在BackgroundWorker的线程,的TableAdapter 的填充。在 RunWorkerCompleted 的方法,我控件绑定到BindingSource的。

和瞧,问题就解决了​​。

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)

解决方案

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.

这篇关于BackgroundWorker_DoWork导致用户界面无响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆