如何使用backgroundworker来打开MdiChildren表单. -在vb.net [英] how to use backgroundworker for open MdiChildren form. -in vb.net

查看:74
本文介绍了如何使用backgroundworker来打开MdiChildren表单. -在vb.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用backgroundworker
在主窗体(mdi父窗体)上打开仪表板的子窗体 或进入vb.net.


how can i open child forms for dash board on main form(mdi parent form) using backgroundworker
or thread into vb.net.


Private Sub Main_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
     bWorker.RunWorkerAsync()
End Sub

Private Sub bWorker_DoWork(ByVal sender As Object, ByVal e As _
  System.ComponentModel.DoWorkEventArgs) Handles bWorker.DoWork
      ViewDashBoard() 'this is my method to show child forms on dash board
End Sub




我用仪表板显示了用户的详细信息,如清单,联系人等,因此
需要更多时间,所以我的主要表单加载时间增加了,这就是为什么我要使用backgroundworker.

请帮帮我. :-)




i used dash board to show user detail like to do list,contacts etc. on main from so its
take more time so my main form loading time is increase thats why i want to use backgroundworker.

help me please. :-)

推荐答案

实际上,最近几天(一周内),我在CP中多次看到类似的问题,因此请从此CP搜索中浏览.

vb.net中的Backgroundworker-CP搜索 [ ^ ]
Actually I have seen similar question in CP many times recent days(within a week), so please browse from this CP search.

Backgroundworker in vb.net - CP search[^]


实际上,您在这里遗漏了重点.请从thatraja给出的链接中检查搜索结果.

您在这里错过了一个重要的事情,即RunWorkerCompleted事件.

基本上,在子bWorker_DoWork中,您可以计算列表和联系人的结果,但是您无法在Do_Work中更新UI控件(表单中的控件).您必须将结果存储在Do_Work的e.Result中.

假设您有一个存储列表的ListBox,计算要存储在ListBox中的内容,然后编写:
Actually you are missing the point here. Do check out the search results from the link given by thatraja.

You have missed an important thing here, the RunWorkerCompleted event.

Basically in the sub bWorker_DoWork, you can calculate the result of the list and your contacts but you cannot update the UI controls(controls in your form) in the Do_Work. You have to store the results in e.Result of the Do_Work.

Suppose you have a ListBox which stores the list, calculate what you wanted to store in the ListBox and then write :
e.Result=list


您无法在此函数中更新ListBox,否则将收到错误消息.

下一步是通过执行以下操作来使用RunWorkerCompleted事件:


You cannot update the ListBox in this function, you will receive an error if you do so.

Next step is to use the RunWorkerCompleted event by doing this :

AddHandler(backgroundWorker.RunWorkerCompleted,AddressOf(back_RunWorkerCompleted))



因此,在函数back_RunWorkerCompleted中,您可以使用e.Result获得Do_Work的结果. (e在RunWorkerCompleted的参数中).
然后,您可以使用该结果更新UI控件.因此,现在您的ListBox可以在此处使用e.Result进行更新.

您可以在此处查看我的博客: http://tarundotnet.wordpress.com/2011/03/14/using-backgroundworker-in-wpf-applications/ [



So in the function back_RunWorkerCompleted, you can get the result of the Do_Work using e.Result. (e is in the Argument of RunWorkerCompleted).
Then you can update your UI Controls using that Result. So now your ListBox can be updated here with the e.Result.

You can check my blog here : http://tarundotnet.wordpress.com/2011/03/14/using-backgroundworker-in-wpf-applications/[^], its in WPF, but i have explained there.

Hope it helped! :)


这篇关于如何使用backgroundworker来打开MdiChildren表单. -在vb.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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