473,386 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Correct method for constantly updating DGV via backgroundWorker

116 64KB
Hi,

I am using a backgroundWorker to access an API for share prices. The response is then parsed and values updated on a DGV on the main UI. The call is made every 30 seconds for new information.

The method below does all this ok however the main UI will freeze during the data retrieval and DGV update despite the fact that the processing is done on the backgroundWorker. I am making sure that only values that have changed are actually re-entered into the DGV.

Is there a proper method for doing this efficiently such that the UI never freezes? Do I need to 'invoke' anything?

Current method as follows.

Expand|Select|Wrap|Line Numbers
  1. Private Sub dataCheckingBackground_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs) Handles dataCheckingBackground.DoWork
  2. Dim checkcount As Integer = 0
  3. Do
  4.    checkcount += 1
  5.    dataCheckingBackground.ReportProgress(checkcount)
  6.    Threading.Thread.Sleep(30000)
  7.    If dataCheckingBackground.CancellationPending = True Then Exit Do
  8. Loop
  9. End Sub
  10.  
  11. Private Sub dataCheckingBackground_RunWorkerCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs) Handles dataCheckingBackground.RunWorkerCompleted
  12. dataCheckingBackground.CancelAsync()
  13. End Sub
  14.  
  15. Private Sub dataCheckingBackground_ProgressChanged(ByVal sender As Object, ByVal e As ProgressChangedEventArgs) Handles dataCheckingBackground.ProgressChanged
  16. ' this gets the third party data and processes into DGV etc
  17. End Sub
  18.  
Many thanks!
Dec 19 '14 #1

✓ answered by robertybob

I'm currently waiting to investigate this but I'm thinking that my problem is that my reportProgress (ie the UI) is doing all the data retrieval and updating and my doWork (ie the BW) is simply dealing with the timing.

I think my doWork should be doing everything possible and only passing the results to reportProgress for it to update the UI.

This should speed things up significantly to the point of being unnoticeable. Will report back when have a chance to check.

2 1331
robertybob
116 64KB
I'm currently waiting to investigate this but I'm thinking that my problem is that my reportProgress (ie the UI) is doing all the data retrieval and updating and my doWork (ie the BW) is simply dealing with the timing.

I think my doWork should be doing everything possible and only passing the results to reportProgress for it to update the UI.

This should speed things up significantly to the point of being unnoticeable. Will report back when have a chance to check.
Dec 20 '14 #2
robertybob
116 64KB
It seems this is the main cause of my problems so for those in a similar situation, remember that the things needed to be done in the background must be in the DoWork and the things required for the UI in the reportProgress.
Dec 28 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

25
by: rokia | last post by:
in a project, I use many,many stl such as stack,list,vctor etc. somewhere the vector's size is more than 2K. is this a efficient way?
1
by: Michael Jasn | last post by:
I had a question about memory management. Please look at the two functions below. Can you answer the two questions in the comments below. Thanks so much. -Mike func1(std::vector<Point>&...
3
by: David Mitchell | last post by:
I have a split app (BE on server - separate FE on each workstation) which is being upgraded with various whistles and bells. To upgrade the FE's I email a small database with an instruction to...
3
by: Dave | last post by:
I have a piece of hardware connected via serial port. I need to send a variety of commands to the box and route the responses back from the receive thread to the correct method call. So e.g. I...
7
by: rhepsi | last post by:
hi all, i have a query... Dim objListItem As ListItem objListItem = CType(cbProjectName.SelectedItem, ListItem)
2
by: Spam Catcher | last post by:
Hi All, I want to bind a datagridview or ListView to a List that is constantly being updated (items are added/removed all the time). Any ideas what the best way is to do this? I tried binding...
0
by: pieandpeas | last post by:
Hi, i'm using a sqldatareader to display information in textboxes, now i need the best 'resource saving' method to save the information held in these textboxes back to the database.. i know there are...
4
by: pieandpeas | last post by:
Hi, i'm using a sqldatareader to display information in textboxes, now i need the best 'resource saving' method to save the information held in these textboxes back to the database.. i know there are...
7
by: Andrus | last post by:
How to get syntactically correct signature which compiles for code template grneration ? I tried code below but it creates syntactically incorrect signature. Andrus. using System; using...
1
by: CopperCircle | last post by:
Hi, I have the following method that checks the state of a checkbox on another form, how can I call this method constantly? or when the user press the mouse? public void Test() {...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.