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
- Private Sub dataCheckingBackground_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs) Handles dataCheckingBackground.DoWork
- Dim checkcount As Integer = 0
- Do
- checkcount += 1
- dataCheckingBackground.ReportProgress(checkcount)
- Threading.Thread.Sleep(30000)
- If dataCheckingBackground.CancellationPending = True Then Exit Do
- Loop
- End Sub
- Private Sub dataCheckingBackground_RunWorkerCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs) Handles dataCheckingBackground.RunWorkerCompleted
- dataCheckingBackground.CancelAsync()
- End Sub
- Private Sub dataCheckingBackground_ProgressChanged(ByVal sender As Object, ByVal e As ProgressChangedEventArgs) Handles dataCheckingBackground.ProgressChanged
- ' this gets the third party data and processes into DGV etc
- End Sub