Home > database >  How do I execute specified function every X seconds
How do I execute specified function every X seconds

Time:09-11

How do I perform an action every 30 seconds?

CodePudding user response:

Add a: Thread.Sleep(30000); at the beginning of your loop, for example:

using System;
using System.Diagnostics;
using System.Threading;
 
public class Example
{
    public static void Main()
    {
        for(int i=0;i<=10;i  )
       {
        Thread.Sleep(30000); //sleeps for 30 seconds
        "Your code running 10 times with a pause every 30 seconds"

       }

    }
}
 
  •  Tags:  
  • c#
  • Related