Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
how can i open child forms for dash board on main form(mdi parent form) using backgroundworker
or thread into vb.net.


VB
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



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. :-)
Posted
Updated 16-Mar-11 23:10pm
v6
Comments
TweakBird 17-Mar-11 2:21am    
can you share your effort.?

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[^]
 
Share this answer
 
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

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 :
VB
AddHandler(backgroundWorker.RunWorkerCompleted,AddressOf(back_RunWorkerCompleted))


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! :)
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900