Hello everyone, I have a problem. I was able to finally make the mechanism for navigating through sites, but now there was a problem, how can I call a function, for example, every 10 seconds. I tried the timer, there is no effect. Here is the code that I tried to stick in a timer:

private void timer2_Tick(object sender, EventArgs e) { timer++; MySqlConnection cnt = new MySqlConnection(strProvider); try { cnt.Open(); MySqlCommand cmd3 = cnt.CreateCommand(); cmd3.CommandText = "SELECT * FROM t_links WHERE ID = '" + timer + "'"; MySqlDataReader readURL = cmd3.ExecuteReader(); while (readURL.Read()) { URL = readURL["URL"].ToString(); webBrowser1.Navigate(URL); labelUrl.Text = "URL: " + URL; } readURL.Close(); } finally { cnt.Close(); } } 
  • one
    And what specifically does not work? - mantigatos
  • one
    I need so that when the timer is triggered (at 10-second intervals), that code is triggered in its event. But it does not work (((and ID does NOT increase - Angus123
  • 2
    Does the timer start at all? Maybe he is in a stagnant state and does not tick ... - mantigatos
  • one
    Yes, it starts after pressing the button. - Angus123

3 answers 3

 WHERE ID = '" + timer + "'"; 

Try this

 WHERE ID = " + timer; 
  • one
    Does not work ( - Angus123

make sure that initially when the program is started, the timer variable is initialized (perhaps it should be assigned 1) and look for where this timer is reset. it’s not infinite to grow =)

    Something I do not see where the timer variable is selected in the timer, by which the sample is taken

    • one
      The code is updated, but there is no effect ( - Angus123
    • one
      Well, then you can say, stick ShowMessage into the timer, find out if it really works. If it works, check the number of records returned by the query - den94
    • one
      Displays a message, but what records need to be changed, I do not know ( - Angus123
    • one
      Tell me how to increase the timer variable (int) by 1 every time how the timer works? So I made a label that shows which ID is currently being viewed, and I noticed that it increases by 1, but after a second it decreases again by 1 .... - Angus123
    • one
      I, of course, am not an expert on c #, but is it possible to simply insert a number in the string "SELECT * FROM t_links WHERE ID =" "+ timer +" '; ? Maybe this is the case? - den94