+ 1
how can I set timer in c#?
Hello friends. I have been trying to do something for some time, but I did not find any results by searching. Please explain to me how to define a code that happens after something happens, for example 300 milliseconds later. Please suggest a code that is not interrupt but just a timer. Also please send concept code. Thankful
2 Antworten
+ 2
using System;
using System.Threading;
class JaScript
{
static void Main()
{
for (int i = 0; i < 5; i++)
{
Console.WriteLine("Sleep for 1 second.");
Thread.Sleep(1000);
}
Console.WriteLine("Main thread exits.");
}
}
+ 1
It's a better approach use Task library for this purposes.
https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task?view=net-6.0
https://code.sololearn.com/cV7NJPf9vgoj/?ref=app