I must say I've been reading this site for a long time and always found what I was looking for. Sadly, today is not the case.
I have a .NET C# Winforms Application that uses MySQL .NET Connector to query a database and fill a DataGridView with the results.
Here is my code:
using (var SqlConn = new MySqlConnection(MyConnectionString)
{
using (var SqlComm = new MySqlCommand("SELECT * FROM my_database.city", SqlConn)
{
using (var SqlAdapter = new MySqlDataAdapter(SqlComm)
{
DataTable SqlOutput = new DataTable();
SqlAdapter.Fill(SqlOutput);
myDataGridView.DataSource = SqlOutput;
}
}
}
The code is working fine. The problem is that, considering that the table has like 20K rows, it takes some time to load and in the meantime, it blocks UI.
Doing some tests, I concluded that the database query Fill() its very fast (it actually takes like 10ms). Therefore, setting DataGridView.DataSource property delays the whole operation.
So my question is, Is there a way to set DataSource propery async? Or maybe a way where I can still use the form while the data is loading?
I was also wondering if there is a better way of doing this, since I would be calling this method every time I do changes on the database table, so I could show the user updated information.
Thanks in advance.