vb.net Loop though typed bound datatable on backgroud worker

Hi I have a typed datatable filled from sql server, bound to 2 gridviews
I need to loop through each row every 5 mins and check if price has changed, if so update it. (the price is coming from an external server)

I did have this on a timer and then loop through each row on same thread but was freezing the UI well it was looping, so now have a background worker to check and update.

the only way i seem to be able to get it to work is to clone the table then loop through rows then on background work completed fill the table again. There must be another way.
If I dont clone the table first the ui freezes and does not recover. Please help.
LVL 3
taz8020Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mlungisi NdlelaFounder of MCSIDevelopers also a software developerCommented:
Have you started the timer inside the background worker?
0
taz8020Author Commented:
no the timer calls the background worker as follows:
if backgroundworkerCheckData.isbusy = false then
backgroundworker.runworkerasync()
End if
0
Mlungisi NdlelaFounder of MCSIDevelopers also a software developerCommented:
In-order for an app to not freeze the GUI you should be calling the timer inside the backgroundworker then your form won't freeze while the timer is running.
0
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

taz8020Author Commented:
but the timer says to run the code in the background worker.

So how would i start and do work with timer in a background worker?
0
Mlungisi NdlelaFounder of MCSIDevelopers also a software developerCommented:
I did have this on a timer and then loop through each row
you need to change to this and on your formload start the backgroundworker and inside the doWork of the backgroundworker you need to call the timer(x).start() and your timer interval should be adjusted so that it will only fire after 5 min as you wish.
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
I would disagree with running the timer in the BGW. Your timer should fire off the BGW and nothing else. After all, the TIMER is not the reason your UI became unresponsive - it was the process of updating your datatable (I'd think).

I'd use the timer, and then start the BGW in that time loop. Better still, create a Class that runs the BGW and fires Events when it's done with the update. You'd pass in the Datatable, start the BGW, and your class could alert the Form when it's finished by raising an event (which you've sinked in the form). when that Form event fires, you could retrieve the datatable from the class and use it to refresh/rebind the grids.
0
taz8020Author Commented:
Hi Scott, I agree i think the problem is because the datatable is bound to 2 gridviews while they are updating. How do i stop/pause the binding without saying datasoure is null?
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
You don't have to "stop" the binding. Just grab a clone of the datatable, pass it to the BGW, allow the BGW to do the update, then rebind.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
taz8020Author Commented:
so something like this

'in timer
dim clonetable as new mydataset.table
clonetable  = .w.mydataset.table

'in background worker
for each row in clonetable
'do update
next

'in complete
me.datagrid.datasorce = clonetable

is that right?
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Actually:

Dim CloneTable as New Datatable
CloneTable = MyDataset.Table(0)

Or, assuming your DataGridView is based on a Datatable:

CloneTable = YourDataGridView.DataSource
0
taz8020Author Commented:
yes but when finished do you rebind to clonetable?
0
taz8020Author Commented:
The two datagrids are bound to a binding source
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
I don't use a BindingSource, so I'm not sure about that. I typically just create a connection to my database, then create a datatable and bind my DGV to that table.

What is the data source of your BindingSource?
0
taz8020Author Commented:
its a datatable fill from sql. so how would you rebind it

so when finished should i say mydatadrid.datasource = clonetable
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
That's all I do to "rebind" my datagridview:

MyDataGridView.Datasource = MyNewDatatable
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.