Click here to Skip to main content
16,014,392 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

In my application I'm trying to ping the DB after every 5 sec to see if any data has been inserted.

I'm using timer and background worker but as I'm new to vb.net I'm totally messed up with the code, please help.

check the code
Private Sub tmrPrfrmDBLd_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmrPrfrmDBLd.Tick

    tmrPrfrmDBLd.Enabled = False
    bgwPrfrmDBLd.RunWorkerAsync(2000)
    tmrPrfrmDBLd.Enabled = True

End Sub
Private Sub bgwPrfrmDBLd_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bgwPrfrmDBLd.DoWork
    Try
        Dim sqlSelNewIss As String = "select IssueID from routTo where visible = 'True' and currownr = " & empID.ToString
        Dim DataSt As New DataSet
        DataSt = DataStore.GetDataset(sqlSelNewIss, sqlConnStr)

        For Each row As DataRow In DataSt.Tables(0).Rows


        Next
'Doing some task
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
End Sub
Private Sub bgwPrfrmDBLd_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles bgwPrfrmDBLd.ProgressChanged
    System.Threading.Thread.Sleep(15000)
End Sub
Private Sub bgwPrfrmDBLd_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bgwPrfrmDBLd.RunWorkerCompleted

End Sub
Posted
Updated 30-Aug-10 9:03am
v2
Comments
Dalek Dave 30-Aug-10 15:04pm    
Edited for Grammar.

1 solution

You could try reading the documentation. RunWorkerAsync is what you need to start a thread. Sleeping is the wrong way to do it. Just use a real timer, that's built into .NET. A thread and a timer are two different things. I suspect the issue is that RunWorkAsync may not work when the thread is disabled, but you don't say what is going wrong.

ProgressChanged does not run on the worker thread, it runs on the main thread, that's what it is for. Threading is complicated, you can't work it out by guessing and really shouldn't be working with SQL, or threads, if you're 'new to VB.NET'.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900