c# - How do I efficiently get data from a database as soon as it updates? -
Therefore, as soon as I see it there, I am trying to get data from the database. I am completing this by executing a timer on every second with a selected query that currently receives the desired information, but by doing so, this program becomes quite difficult every second, so it looks really bad.
My question is, is there a better way to get data as a database update? Or maybe the way I am doing this is a better way of optimizing, so it does not make lagaspeaks in every second?
Private Zero Update Timer_Tick (Object Sender, EventArgs e) {string mySQLConnection = "& lt; connection_string>"; // MySqlConnection connection left out for security purposes = New MySqlConnection (mySqlConnection); & Lt; String & gt; ID = new list & lt; String & gt; (); & Lt; String & gt; Source = new list & lt; String & gt; (); & Lt; String & gt; Message = new list & lt; String & gt; (); Use (connection) {connection.Open (); MySqCommand command = connection.CreateCommand (); Command.CommandText = "SELECT id, source, message table WHERE target = @address"; Command. Parameter. Advait Value ("@ address", ipadder); MySqlDataReader Reader = command.ExecuteReader (); While (reader.Read ()) {id.Add (reader.GetString (0)); Source.Add (reader.GetString (1)); Message.Add (reader.GetString (2)); } Command. Parameter. Clear (); Connection.Close (); }}
To check that a table has been updated, you can It can:
show the lock status like 'tabletname';
and then you will need to find the update field:
if (dr.Read ()) {if (dr ["Update_time"]! = Null | | DR ["update_time"]! = System.dibil.value) {result = (date time) Dr. ["update_time"]; }}
Compare this with the final result, which you can see to see if they are different.
It should be less intensive on DB and App.
Comments
Post a Comment