so, i got my threading working, using a background worker. the problem im having now is updating a text label on a form. i have a background worker running to test some state, so the background worker is set to run as long as the program is running. every time it fires, it call a function. this function will test a comport for activitity. if there is activity, i want to change a label's text. its not working, though. heres what i got:
and heres the function it calls:Code:Public Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork Dim j As Integer = 0 Dim i As Integer = 0 Debug.Print("bg worker begin") While i = j If BackgroundWorker1.CancellationPending Then i = 2 e.Cancel = True BackgroundWorker1.Dispose() Debug.Print("bg worker middle") Exit While Else CheckForNew() End If End While Debug.Print("bg worker end") End Sub
ive tried using Progress changed event, as well. although the event fires, it still wont change the label.Code:Public Sub CheckForNew() Debug.Print("checkfornew begin") '...stuff not related Dim con As OleDbConnection Dim constring As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & CurDir() & "\MyDb.mdb" con = New OleDbConnection(constring) Dim ds As New DataSet Dim da As OleDbDataAdapter Dim dt As DataTable Dim dr As DataRow da = New OleDbDataAdapter("SELECT * FROM tblInboxMsg where MsgStatus='New'", con) da.Fill(ds) counter = 0 For Each dt In ds.Tables For Each dr In dt.Rows counter = counter + 1 Next Next Debug.Print("chekcfornew end") form1.label10.textt = counter 'nothing happens here End Sub
any suggestions?
thanks
jason




Reply With Quote