Home > Blockchain >  What code to use to track how much time has passed with c#?
What code to use to track how much time has passed with c#?

Time:09-10

I want to do a loop that every 30 seconds do an action, but I don't know how to make it checks if 30 seconds has passed.

I know there's Stopwatch and DateTime, I just didn't get how to use them.

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