Question Locked

Background worker and datagridview in visual basic

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi I've been struggling to understand how this works for ages. I've read loads of examples but I don't seem to get anywhere with it.

I am trying to get a datagridview to requery on a timer. I want this to run on a background worker so it doesn't kill the program when it query's

Here is a my code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.NewJobsTableAdapter.Fill(Me.Report_databaseDataSet.NewJobs)
End Sub

Private Sub BackgroundWorker1_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
End Sub

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Me.BackgroundWorker1.RunWorkerAsync()
End Sub

Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
LoadData()
End Sub

Private Sub LoadData()
Me.DataGridView9.DataSource = DBNull.Value
Me.DataGridView9.DataSource = NewJobsRedBindingSource
Me.NewJobsTableAdapter.Fill(Me.Report_databaseDataSet.NewJobs)
End Sub

I am not sure what to put in the dowork event. I just seem to get an error about unsafe threading. Any help in getting this to work would be greatly appreciated

1 reply

This discussion is closed to new replies.