0

I am looking for a way to show a notification when a record has been inserted.

This is what i have:

public static void Method()
{

    int count = int.MinValue;
    int prev_count = int.MinValue;

    //Get count from MySQL table
    using (var conn = new MySqlConnection(ConnectionString.ConnString))
    {
        conn.Open();

        var cmd = new MySqlCommand("select count(*) from table;", conn);
        count = Convert.ToInt32(cmd.ExecuteScalar());

        conn.Close();

    }

    if (count != prev_count)
    {
        PopupNotifier popup = new PopupNotifier();
        popup.TitleText = "Record";
        popup.ContentText = "New record has been added.";
        popup.Popup();

        prev_count = count;
    }
}

I have tried this: https://stackoverflow.com/a/62193334/13678741

But that simply runs the notification every 5 seconds.

When the form loads - I need to check the number of records and constantly compare it to previous number, if changed then notify user.

What is an ideal method to notify user if a record has been added to the table? Is mine doable?

LionBar
  • 1
  • 2
  • Does this answer your question? [How to run a function every minute comparing old number to new number?](https://stackoverflow.com/questions/62191182/how-to-run-a-function-every-minute-comparing-old-number-to-new-number) – Alejandro Jun 04 '20 at 11:54
  • This is basically the very same question you asked hours ago. – Alejandro Jun 04 '20 at 11:54
  • One way maybe is to implement database on change trigger and watch it with SignalR or similar? – onedevteam.com Jun 04 '20 at 11:59
  • Depending on what your requirements are, this could be useful [Execute Shell script/command from MySQL Trigger/Stored Procedure](https://stackoverflow.com/questions/29820937/execute-shell-script-command-from-mysql-trigger-stored-procedure) – Cleptus Jun 04 '20 at 12:32

0 Answers0