MySQL Inside Timer Not Returning Updated Data

turbobaltss06

New member
Joined
Feb 3, 2014
Messages
4
Programming Experience
5-10
So i am having a little issue with some code i have.. Its inside a timer and when it runs it just keeps the same data never sees that it does an update to the mysql and makes 0 become 1 if there is data there.

How do i get it to refresh the sql query so it sees that the data has indeed changed?

Here is my code

VB.NET:
 Public Function updateMessageCore()

        Connect.ConnectDatabase()


        sql_chat_balloon_tip_one = "select * from wp_bp_chat_client_user_core where user_id ='" & login.usrLoggedID & "' and balloon_tip_status = '0'"






        Dim balloon_tip_cmd_one = Connect.doCMD(sql_chat_balloon_tip_one)


        While balloon_tip_cmd_one.Read()


            balloon_tip_data_one &= balloon_tip_cmd_one.GetString(5) & ","


        End While


        balloon_tip_cmd_one.Close()


        Console.Write(balloon_tip_data_one)


        'number two call


        Dim balloon_break As String = balloon_tip_data_one
        Dim balloon_breaks() As String
        balloon_breaks = balloon_break.Split(",")


        For Each balloon_tips As String In balloon_breaks


            sql_chat_balloon_tip_two = "select * from wp_bp_chat_client_message where user_id ='" & login.usrLoggedID & "' and chat_session_id = '" & balloon_tips & "' ORDER BY id DESC"


            Dim balloon_tip_cmd_two = Connect.doCMD(sql_chat_balloon_tip_two)


            While balloon_tip_cmd_two.Read()






                NotifyIcon1.ShowBalloonTip(2000, "New Message", balloon_tip_cmd_two.GetString(3), ToolTipIcon.Info)


                Console.Write(balloon_tip_cmd_two.GetString(3))


                'doAction("UPDATE wp_bp_chat_client_user_core SET balloon_tip_status = '1' WHERE chat_session_id = '" & balloon_tips & "'")




            End While


            balloon_tip_cmd_two.Close()


        Next


        For Each balloon_tips As String In balloon_breaks


            doAction("UPDATE wp_bp_chat_client_user_core SET balloon_tip_status = '1' WHERE chat_session_id = '" & balloon_tips & "'")


        Next


        Connect.DisconnectDatabase()




    End Function


    Private Sub timer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles timer.Elapsed




        updateMessageCore()




    End Sub
 
Did you add your Timer to your form in the designer or did you create it in code? Is the SynchronizingObject property of the Timer set? If so, what to?

I did it like this, I did not use the timer u drop on to the form.

VB.NET:
Private WithEvents timer As New System.Timers.Timer



            timer.Enabled = 1
            timer.Interval = 3000
            timer.SynchronizingObject = Me
 
There is no one Timer that you can add to a form in the designer. The Windows.Forms.Timer is in the Toolbox by default but the Timers.Timer, which you're using, is a component as well so it can also be added to the Toolbox and, from there, added to a form in the designer. The main difference between the two is that the Windows.Forms.Timer is intended to raise its Tick event on the UI thread while the Timers.Timer raises its Elapsed event on a secondary thread by default. If you set the SynchronizingObject property though, it will also raise its Elapsed event on the UI thread. As such, you gained nothing by not using the Windows.Forms.Timer that is in the Toolbox by default.

Unfortunately, I had thought/hoped that the issue would be related to multi-threading because you had not set the SynchronizingObject. That theory is out the window so I'll have to look more closely at your code, which is harder to read than necessary because of all the unnecessary empty lines.

By the way, the Enabled property of the Timer is type Boolean so you should be assigning a Boolean value to it, i.e. True or False, not an Integer. I strongly recommend that you turn Option Strict On in the project properties and also in the IDE options, so that it will be On by default for all future projects. That will help you use the correct data types at all times, amongst other things.
 
There is no one Timer that you can add to a form in the designer. The Windows.Forms.Timer is in the Toolbox by default but the Timers.Timer, which you're using, is a component as well so it can also be added to the Toolbox and, from there, added to a form in the designer. The main difference between the two is that the Windows.Forms.Timer is intended to raise its Tick event on the UI thread while the Timers.Timer raises its Elapsed event on a secondary thread by default. If you set the SynchronizingObject property though, it will also raise its Elapsed event on the UI thread. As such, you gained nothing by not using the Windows.Forms.Timer that is in the Toolbox by default.

Unfortunately, I had thought/hoped that the issue would be related to multi-threading because you had not set the SynchronizingObject. That theory is out the window so I'll have to look more closely at your code, which is harder to read than necessary because of all the unnecessary empty lines.

By the way, the Enabled property of the Timer is type Boolean so you should be assigning a Boolean value to it, i.e. True or False, not an Integer. I strongly recommend that you turn Option Strict On in the project properties and also in the IDE options, so that it will be On by default for all future projects. That will help you use the correct data types at all times, amongst other things.

Ok, please let me know if u find anything out. Sorry if i my code is hard to read but for me it is not hard to read.
 
Perhaps you could explain to us exactly what you expect to happen and what actually does happen.

well it should query the sql code and then update the balloon_tip_status to 1 if it finds balloon_tip_status with 0 in the database. it does that. but the issue is when the timer runs it just never sees that there is new data there or that the values have changed. so it just keeps showing the same old data even though the balloon_tip_status is set to 1 and not 0 anymore.
 
Back
Top