I a'm reading values from raspberry pi mysql database with visual studio c#
If the database is not available and I am trying to read from it, the c# app
freezes for about 15 seconds.
Is it possible to make it not to freeze when checking if the database is available?
Her is the code
If the database is not available and I am trying to read from it, the c# app
freezes for about 15 seconds.
Is it possible to make it not to freeze when checking if the database is available?
Her is the code
C#:
string connString = "SERVER='192.168.86.41';DATABASE='spaceinformation';UID='******';PASSWORD='******'";
private void FormMeasurement_Load(object sender, EventArgs e)
{
try
{
using (var connection = new MySqlConnection(connString))
{
connection.Open();
query = "select * from weather";
using (var command = new MySqlCommand(query, connection))
{
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
listBoxMeasurement.Items.Add(string.Format("Temperature: {0} Humidity: {1} Date: {2}", reader.GetString("temp"), reader.GetString("hum"), reader.GetString("datecreated")));
}
}
}
connection.Close();
}
}
catch
{
MessageBox.Show("Database is not available for moment!");
listBoxMeasurement.Enabled = false;
}
}