Results 1 to 4 of 4

Thread: [RESOLVED] More threading issues: updating control

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Location
    Botswana
    Posts
    107

    Resolved [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

  2. #2
    Frenzied Member obi1kenobi's Avatar
    Join Date
    Aug 2007
    Posts
    1,091

    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

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Location
    Botswana
    Posts
    107

    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

  4. #4
    Frenzied Member obi1kenobi's Avatar
    Join Date
    Aug 2007
    Posts
    1,091

    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
  •  



Click Here to Expand Forum to Full Width