rgerculy
rgerculy

Reputation: 481

Awesomium freezes / not responding

I have a traffic exchange website and I want to convert it into an windows application using C# winform with Awesomium 1.7.5. The basic setup is ready but there is a problem with Awesomium. After visiting a few websites slows down and the freezes entirely ( Not Responding ).

           public Form1()
        {
            InitializeComponent();

            Text = "Traffic Exchange";
            WindowState = FormWindowState.Maximized;
            timer1 = new System.Windows.Forms.Timer();
            timer1.Tick += new EventHandler(timer1_Tick);
            int user_id = Properties.Settings.Default.user_id;
            string user_id_s = user_id.ToString();
            toolStripLabel2.Text = user_id_s;

            if (Properties.Settings.Default.user_id == 0)
            {
                toolStripLabel3.Visible = true;
                toolStripButton3.Visible = false;
            }
            else
            {
                toolStripButton3.Visible = true;
                toolStripLabel3.Visible = false;
            }
         }

        private void toolStripButton3_Click_1(object sender, EventArgs e)
        {
// starting the traffic traffic exchange
            LoadUrl();
            StartTimer();
        }


         private void LoadUrl()
        {
            try
            {
                string MyConnection2 = "*******";
                string Query = "select * from ****** where status = 1 AND credits > 5 ORDER BY rand() LIMIT 1";
                MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
                MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
                MyConn2.Open();
                using (MySqlDataReader DR = MyCommand2.ExecuteReader())
                {
                    while (DR.Read())
                    {
                        string WebURL = Convert.ToString(DR.GetValue(*));
                        string WebSurfSec = Convert.ToString(DR.GetValue(*));


                        int result = Convert.ToInt32(WebSurfSec);
                        int sec_to_mil = result * 1000;
                        toolStripLabel5.Text = WebSurfSec;

                        //toolStripStatusLabel2.Text = result.ToString();
                        //toolStripStatusLabel3.Text = sec_to_mil.ToString();
                        webControl3.Source = new Uri(WebURL);
                        toolStripTextBox1.Text = WebURL;
                        toolStripLabel6.Text = toolStripTextBox1.Text;


                        timer1.Interval = sec_to_mil; // in miliseconds

                    }
                }
                MyConn2.Close();

               // WebCore.ReleaseMemory();

             //  webControl3.Update();
             //   Thread.Sleep(500);



            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }
      private void timer1_Tick(object sender, EventArgs e)
        {
            LoadUrl();
        }
      private void StartTimer()
        {
            timer1.Start();
        }

So LoadUrl() it's a loop. When the app is started loads in the traffic exchange website, a little bit slow but it works and you can go form a page to another without freezing but when the exchange is in action ( LoadUrl() ) after 5 minutes the app is dead. I've been searching for a solution all day and ended up with nothing, couldn't find a solution the problem.

Upvotes: 1

Views: 394

Answers (1)

Ron Beyer
Ron Beyer

Reputation: 11273

The timer should not be recreated each time you loop. What is happening is that you are creating multiple event handlers each time you loop. Creating the handler once in the constructor and starting the timer in the button click routine is the right way.

You can change the interval inside the loop, but avoid adding another Start() method call there.

Upvotes: 2

Related Questions