-1

I have C#.NET program and I want to check something every 2 seconds until my form is closed. This cycle doesn't enable with user for other hand when user run my C#.NET form cycle is start until form closed.

For example I want to check internet connection when my form is used. I don't like checking the connection in form.load;. I want to check connection is every time.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
nace
  • 61
  • 1
  • 6

1 Answers1

-1

this code is worked :

cycle Timer in winForm c#.NET

 using Timer = System.Windows.Forms.Timer;
 private void Form1_Load(object sender, EventArgs e)
{
    Timer MyTimer = new Timer();
    MyTimer.Interval = (45 * 60 * 1000); // 45 mins
    MyTimer.Tick += new EventHandler(MyTimer_Tick);
    MyTimer.Start();
}
private void MyTimer_Tick(object sender, EventArgs e)
{
    //Check for internet connection or some other work here
    Timer MyTimer = new Timer();
    MyTimer.Interval = (45 * 60 * 1000); // 45 mins
    MyTimer.Tick += new EventHandler(MyTimer_Tick);
    MyTimer.Start();
}
nace
  • 61
  • 1
  • 6