D
D
Demogor2013-05-10 09:29:34
MySQL
Demogor, 2013-05-10 09:29:34

Synchronizing changes in a table with a C# application?

Good day to all!
There was a need to transfer changes in the table to the application for subsequent processing and editing of a separate file based on the changes received.
Currently implemented like this:

private void button3_Click(object sender, EventArgs e)
        {
            Initialize(); //подключаемся к бд
            prev_list = _query("select * from log"); //получаем текущее состояние таблицы
            Thread th = new Thread(checkDB); // запускаем "монитор"
            th.Start(500);
        }

bool run = true;
void checkDB(object sender)
        {
            while (run)
            {
                var curr_list = _query("select * from log"); //текущее состояние лог-таблицы
                if (!ListEquals(curr_list, prev_list)) //если не равно предыдущему
                {
                    info.Items.Add("Database changed");
                    info.Items.Add(string.Join(",", curr_list)); //выводим состояние таблицы
                    prev_list = curr_list;
                    _query("truncate table log"); //чистим лог к едрене фене
                }
                Thread.Sleep((int)sender);
            }
        }

The log table itself is updated using a MySQL trigger.
And yes, I know about timers, in the thread I implemented a slightly different aspect to check.
Actually, the question is - are there more adequate methods for responding to update / insert in a mysql table (performed through another application) than the current version?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AlexeyVD, 2013-05-10
@AlexeyVD

Instead of pulling out the entire log table each time, isn’t it easier to insert a line with information about the change or changed lines (depending on what you need) into some state table when it changes, and monitor this small table from your application.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question