在哪里实现BackgroundWorker。 Winforms C#

发布于 2024-10-01 06:22:42 字数 817 浏览 4 评论 0原文

我使用 DevExpress XtraTreeList 创建了一个 UserControl。基本上在这个用户控件中我使用的是库存项目。超过30,000。现在,当我在类型化数据集中加载完整的表时,几乎需要 6-8 秒。

构建用户控件的目的是可重用性。这样我们就可以在应用程序的其他部分使用它。

现在我在 Winform 中使用这个 UserControl,该用户控件位于窗体的左侧,它将用作菜单。假设用户通过展开节点来单击所需的项目,当选择节点时,将获取其进一步的详细信息并将其显示在 from 中。到目前为止,一切都很好。

现在真正的问题是,在与其他控件相同的形式中,我们有一个 Devexpress XtraButtonEdit(使用右侧的文本框和按钮构建)。此按钮编辑在其文本框中显示当前选定的项目(来自树菜单用户控件)代码,当我们单击按钮编辑按钮时,我们将加载另一个表单作为模型并显示相同的用户控件(来自 DevEpress 的 XTRATreeList)。唯一的问题是,当我将这个新表单作为模型时。树再次需要时间来加载,这看起来有点尴尬。

为了纠正这个问题,我正在尝试实现后台工作线程,但有点困惑我应该在哪里实现该后台工作。在用户控件或表单中。

如果我在 UserControl 中实现该后台 worder,那么我如何访问此 BackgroundWorker 线程并在主窗体上执行它,在主窗体上我使用左侧的 UserControl 作为菜单。实际上我想要的是当用户单击 ButtonEdit 控件并加载表单时,它应该在 2 秒内像 Flash 或 max 一样加载......请帮助......并执行它。

我希望ppl能理解我的问题。

如果有人发现任何困难请告诉我......

问候,

I have created a UserControl using a DevExpress XtraTreeList. Basically in this user control I am using inventory Items. which are more than 30,000. Now when I load the complete table in my typed DataSet it takes almost 6-8 seconds.

The purpose to build the usercontrol is reuseability. So that we can use it in other parts of the application.

Now I am using this UserControl in a Winform, where this usercontrol is place in the left hand side on the form where it will be used as a Menu. The user is suppose to click its desired item by expanding the nodes and when the nodes is selected and then its further details will be fetched and will be displayed in the from. So far so good.

Now the reals issue is that in the same form along with other controls, we have a Devexpress XtraButtonEdit(build using a textbox and a button on the right handside). This buttonEdit is displaying the currently selected Item(from the treeMenu UserControl) code in its textbox, when we are clicking the buttonEdit button then we are loading another form as a model and displaying the same UserControl (XTRATreeList from DevEpress). The only issue is that when I am laoding this new form as a model. The tree again takes time to load which looks bit awkward.

To rectifiy this issue, I am trying to implement the Background worker thread, but bit confused that where should I implement that backgroundWork. In the User Control or in the form.

If I implement that Background worder in the UserControl then how can I access this BackgroundWorker thread and execute it on the main Form where I am using the UserControl on the left hand side as a Menu. Actually what I want is when user clicks the ButtonEdit control and the form loads, it should load like a flash or max in 2 sec....please help.... and execute it.

I hope that ppl will understand my issue.

If somebody finds any difficulty plz let me know....

Regards,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

溺深海 2024-10-08 06:22:42

您不必“访问此BackgroundWorker线程并在主窗体上执行它”。

用户控件可以包含其自己的 Bgw。您需要一个同步方法(在 UC 上)来启动它。然后处理 UC 内已完成(可能还有进度)的事件。

但数据加载速度不会更快,您只需解冻主 GUI。

You don't have to "access this BackgroundWorker thread and execute it on the main Form".

A user control could contain its own Bgw. You nee a synchronous method (on the UC) to start it. Then handle the completed (and mayb progress) events inside your UC.

But the data won't load any faster, you only unfreeze your main GUI.

无需解释 2024-10-08 06:22:42

如果延迟是在加载树的代码中引起的,那么您应该“线程”该部分。我建议阅读 C# in a Nutshell 中的示例章节: http://www.albahari.com/threading/< /a>.它们涵盖了 C# 4.0,但如果您正在使用 C# 3.0,您应该能够将大部分概念应用到 C# 3.0。

If the delay is caused in the code that loads the tree, then you should "thread" that part. I would recommend reading this sample chapter from C# in a Nutshell: http://www.albahari.com/threading/. They cover C# 4.0, but you should be able to apply most of the concepts to C# 3.0 if that's what you are using.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文