Answer the question
In order to leave comments, you need to log in
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);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question