|
-
Sep 21st, 2007, 02:57 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] [2005] background worker
hi all,
is it possible to use backgroundworker when loading database data / filling datatables?
i did the ff: codes below but it doesn't work right... myDataTable is not being filled and the progressbar doesn't do anything.
Code:
Private Sub vo01_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.BackgroundWorker1.RunWorkerAsync()
End Sub
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
Me.myTableAdapter.Fill(Me.DataSet.myDataTable)
End Sub
Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
ProgressBar1.Value = e.ProgressPercentage
End Sub
please help... thanks.
VB Version: Microsoft Visual Studio 2008 Professional Edition
.NET Version: Microsoft .NET Framework Version 3.5
OS: Windows XP SP3
-
Sep 21st, 2007, 07:49 AM
#2
Re: [2005] background worker
Your ProgressBar is never going to do anything because you never call the ReportProgress method so the ProgressChanged event is never raised. Even if you wanted to that would do no good though, because you can't get any feedback during the Fill method anyway. The table is empty before and populated after and there's no way to know where you are at in between. See the link below for an example of getting progress feedback from a BGW.
http://vbforums.com/showthread.php?t=471889
As for your DataTable not being filled, how do you know? How are you checking that? Also, what value does the Fill function return? That's the number of rows retrieved, so if that's zero it means that your query didn't find any matching rows. In that case your code is fine, but you're either using the wrong query or querying the wrong data.
-
Sep 22nd, 2007, 12:14 PM
#3
Thread Starter
Hyperactive Member
Re: [2005] background worker
 Originally Posted by jmcilhinney
Your ProgressBar is never going to do anything because you never call the ReportProgress method so the ProgressChanged event is never raised. Even if you wanted to that would do no good though, because you can't get any feedback during the Fill method anyway. The table is empty before and populated after and there's no way to know where you are at in between. See the link below for an example of getting progress feedback from a BGW.
i see... i guess instead of using a progress bar i think i'm just gonna use some sort of animation to let the user know that the application is doing something.
 Originally Posted by jmcilhinney
As for your DataTable not being filled, how do you know? How are you checking that? Also, what value does the Fill function return? That's the number of rows retrieved, so if that's zero it means that your query didn't find any matching rows. In that case your code is fine, but you're either using the wrong query or querying the wrong data.
what i did is i added codes to disable the form at form_load and then do the filling and enable the form at the backgroundworker's runworkercompleted event... but my form's txtboxes, comboboxes etc remains to be empty until i click on the next record button.
VB Version: Microsoft Visual Studio 2008 Professional Edition
.NET Version: Microsoft .NET Framework Version 3.5
OS: Windows XP SP3
-
Sep 23rd, 2007, 06:02 PM
#4
Re: [2005] background worker
If you can click the Next Record button and get data then I would suggest that your DataTable must be being populated. If it wasn't then how would you be able to see any data at all? I asked you in my previous post what value your Fill method returned and you have chosen not to answer. If you want our help then I suggest you provide the information we need to help when we ask for it.
i guess instead of using a progress bar i think i'm just gonna use some sort of animation to let the user know that the application is doing something.
You can still use a ProgressBar for that, with its Style property set to Marquee.
-
Sep 23rd, 2007, 08:35 PM
#5
Thread Starter
Hyperactive Member
Re: [2005] background worker
hi,
i tried to do what you said by using these codes..
Code:
Dim intNo As Int32
intNo = Me.ableAdapter.Fill(Me.DataSet.Table)
Debug.WriteLine(intNo)
it returned 10.
the datatable is being filled with no problems like what you said.
but when i check the binding navigator the BindingNavigatorPositionItem says 0 of 0 which makes me think its not going to the first record.
so i tried to experiment with it... on the BackgroundWorker1_RunWorkerCompleted i tried putting in different lines of codes like..
1. Me.CustomerBindingSource.ResetBindings(True) -- works fine.
2. Me.CustomerBindingSource.Position = 1 -- will work as long as its not 0.
3. Me.CustomerBindingSource.MoveNext and Me.CustomerBindingSource.MoveLast are both working.
when putting any of the codes above, it populates the textboxes, comboboxes etc. with the data... not sure why the TableAdapter.Fill is not enough and why i need to put these codes for it to populate my controls.
VB Version: Microsoft Visual Studio 2008 Professional Edition
.NET Version: Microsoft .NET Framework Version 3.5
OS: Windows XP SP3
-
Sep 23rd, 2007, 10:00 PM
#6
Re: [2005] background worker
My guess would be because you are populating the DataTable outside the UI thread. You cannot access members of a control outside the UI thread, and having your data changes propagate to the UI would require that. As such I'm guessing that the BindingSource is smart enough to not even try. You're doing the righ thing by calling ResetBindings in the RunWorkerCompleted event handler. The reason setting the Position to zero wouldn't work is that it is already zero, so there's no change so no event will be raised.
-
Sep 25th, 2007, 01:05 AM
#7
Thread Starter
Hyperactive Member
Re: [2005] background worker
i see... well this is good enough for me.
thanks for the info.
VB Version: Microsoft Visual Studio 2008 Professional Edition
.NET Version: Microsoft .NET Framework Version 3.5
OS: Windows XP SP3
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|