|
-
Sep 11th, 2008, 03:33 AM
#1
Thread Starter
Lively Member
[RESOLVED] More threading issues: updating control
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:
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
and heres the function it calls:
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
ive tried using Progress changed event, as well. although the event fires, it still wont change the label.
any suggestions?
thanks
jason
I am using Microsoft Visual Basic 2008 Express Edition. I use Access for my data base
-
Sep 11th, 2008, 04:12 AM
#2
Frenzied Member
Re: More threading issues: updating control
Try this link: http://www.vbforums.com/showthread.php?t=498387
Also, if the ProgressChanged event doesn't change the label, perhaps the code which should change the label is incorrect. I see the Form1.Label10.Text property, which would mean that you are trying to change a label on a different form, right? If so, then you'd be better off creating a new event on your current form and handling it from the other one.
Please rate helpful ppl's posts. It's the best 'thank you' you can give 
-
Sep 12th, 2008, 05:55 AM
#3
Thread Starter
Lively Member
Re: More threading issues: updating control
cool. got it working. thanks
I am using Microsoft Visual Basic 2008 Express Edition. I use Access for my data base
-
Sep 13th, 2008, 06:09 AM
#4
Frenzied Member
Re: [RESOLVED] More threading issues: updating control
You're welcome anytime.
Please rate helpful ppl's posts. It's the best 'thank you' you can give 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|