Program stopped responding - c # Windows Form

1

I'm doing a program in C # that basically does (large) queries to a MySql database. When I run the program via Visual Studio, everything happens perfectly. But when I do this by the executable, when the button that performs the queries and handles them is pressed, the application stops responding. Even locking, after a while the program presents the result. However, I'd like you to keep track of progress via the progress bar.

Since I am a "programmer" only on a short time, I simply program everything, using only the most complex language features. So I'd like to know, in general, what are the main causes of this difference in performance / interaction between Debug mode and release mode. Below the code used for the query.

                MySqlCommand command = new MySqlCommand(sql, con);
                MySqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    for (int n = 1; n <= numVar; n++)
                    {
                        if (!Convert.IsDBNull(reader.GetValue(n-1)))
                        {
                            resultados[n - 1].Add(Convert.ToDouble(reader.GetValue(n - 1)));
                        }
                        else 
                        {
                            resultados[n - 1].Add(0); 
                        }



                    }
                }

                progressBar1.PerformStep();

And the queries used are usually of this type:

     SELECT 
    ROUND(SUM(HT_MA4_SBX_SEG.VL_M4000251), 2), 
    ROUND(SUM(HT_MA4_SBX_SEG.VL_M4000258), 2),
    ROUND(SUM(HT_MA4_SBX_SEG.VL_M4000265), 2),
    ROUND(SUM(HT_MA4_SBX_SEG.VL_M4000272), 2),
    ROUND(SUM(HT_MA4_SBX_SEG.VL_M4000279), 2),
    ROUND(SUM(HT_MA4_SBX_SEG.VL_M4000286), 2),
    ROUND(SUM(HT_MA4_SBX_SEG.VL_M4000293), 2),
    ROUND(SUM(HT_MA4_SBX_SEG.VL_M4000300), 2),
  ..
    ROUND(SUM(HT_MA4_SBX_SEG.VL_M4000398), 2)
     FROM HT_MA4_SBX_SEG WHERE HT_MA4_SBX_SEG.TS_SAMPLETM BETWEEN STR_TO_DATE('13/07/2015', '%d/%m/%Y') AND STR_TO_DATE('14/07/2015', '%d/%m/%Y')

The tables used have approximately 5,300,000 rows of data.

    
asked by anonymous 30.08.2015 / 00:50

1 answer

1

I was able to solve the problem. As the colleagues said in the comments, the problem was that the whole code was in the same thread, causing the rest of the form to wait unmodified. Finally, I used the BackGround Worker class.

Within DoWorker I put all the code that does the mysql query and treats the result. I have had some problems regarding the amount of variables that can be passed to the BackGround Worker, to solve this, I used the answer given in this topic . Thank you for your help.

    
31.08.2015 / 00:27