Sharabeel Shah
Sharabeel Shah

Reputation: 91

Message box quits after severals clicks to exit in win form C#

After the code has run it produces a message box which is displayed correctly.However, it takes a few press of the ok/cross to quit it. I cannot seem to find a problem in order to solve this.

private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
    List<String> BlockList = new List<String>();
    con.Open();
    SqlCommand cmd = con.CreateCommand();
    cmd.CommandType = CommandType.Text;
    cmd.CommandText = "select BlockList from BlockList";
    cmd.ExecuteNonQuery();
    using (SqlDataReader objReader = cmd.ExecuteReader())
    {
        if (objReader.HasRows)
        {
            while (objReader.Read())
            {                
                string item = objReader.GetString(objReader.GetOrdinal("BlockList"));
                BlockList.Add(item);

                string[] BlockArray = BlockList.ToArray();

                for (int i = 0; i < BlockArray.Length; i++)
                {
                    if (e.Url.Equals(BlockArray[i]))
                    {
                        e.Cancel = true;
                        MessageBox.Show("Booyaa Says No!", "Blocked"); // Block List Error Message
                        player.SoundLocation = "nono.wav";
                        player.Play();

                    }
                }
            }

        }
    }

    con.Close();
}

Upvotes: 1

Views: 36

Answers (1)

JEV
JEV

Reputation: 2504

Hard to tell exactly but I imagine it might have something to do with the fact you are putting up a MessageBox, which will halt the UI thread, during the read to your database. Any reason you can't wait until the read has finished?

Upvotes: 2

Related Questions