0

I have a software that reads data from my router.

Everything is working - but I have to press a buton called "refresh" if I want to see the data refreshing...

This should work in the background after I have connected to the device.

How can I do it automatically - every 10 seconds?

I have tried this: Add timer to a Windows Forms application

It seems my code doesn't know System.Windows.Forms.Timer class.

plori
  • 331
  • 3
  • 7
David12123
  • 119
  • 4
  • 15

1 Answers1

0
Use System.Windows.Forms.Timer class
private Timer timer1; 
public void InitTimer()
{
    timer1 = new Timer();
    timer1.Tick += new EventHandler(timer1_Tick);
    timer1.Interval = 10000; // 10 seconds / 10000 MillSecs
    timer1.Start();
}

private void timer1_Tick(object sender, EventArgs e)
{
    isonline();
}

Thanks to Stecya in Execute specified function every X seconds

Cesar
  • 453
  • 9
  • 21
  • Its seem I don't have System.Windows.Forms.Timer?? can it be ? – David12123 Aug 29 '18 at 10:19
  • @David12123 Right-click your project in Solution Explorer and select Add reference... and then find System.Windows.Forms and add it. When Windows.Forms is added you can use the Timer class. – Cesar Aug 29 '18 at 10:21
  • the all c# code is a windows application form (and working) , but when I write this line "using System.Windows.Forms.Timer" it say Timer is type not a namespace – David12123 Aug 29 '18 at 10:25
  • @David12123 change it to `using System.Windows.Forms;` instead. But it sounds like you're running a console app, if that's not already available. If that's the case you probably should use one of the *other* `Timer` classes instead – pinkfloydx33 Aug 29 '18 at 10:44
  • I don't ,this is a windows forom application...... I found solution here https://www.youtube.com/watch?v=98c200lL-OY – David12123 Aug 29 '18 at 10:57