# C# Programming > C-Sharp Programming >  Mysql database freezes with Visual Sudio C#

## kenne76

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


 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;
            }
        }

----------


## salem_c

Basically, don't do long duration blocking operations on the UI thread.

This should be moved to a worker thread of some sort, and "listBoxMeasurement.Items.Add" would become a message from the worker to your UI thread, which would then do the actual listBoxMeasurement.Items.Add call.

----------

