+ 17
How to make timer/delay?
Does anyone know how to make a delay function? Like a function that 'pauses' the system/proccess for a few second before resuming. For example : Console.WriteLine("Please wait 3second"); //Insert a delay/timer here that activates the next line of code after 3seconds Console.WriteLine("You just wasted 3seconds of your life! "); (or does even SoloLearn have the function in their programming tool in the first place)
15 Réponses
+ 5
Ok thanks. Now I figured out the problem. SoloLearn programme doesn't fully support Thread.Sleep programe
+ 14
using System.Threading;
Thread.Sleep(interval);
+ 5
using System;
using System.Threading;
namespace std
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Please wait 3second");
Thread.Sleep(3000);
Console.WriteLine("You just wasted 3seconds of your life! ");
}
}
}
+ 4
Note that the interval is in milliseconds
+ 4
What I meant was that I wanted the system to print out text "a" for the user to see first, then after a few seconds it will print out text b
+ 2
I created a timer example in javascript using the setInterval function. You can check it out here: https://code.sololearn.com/WkvkWFcUN9bh
Edit: I went through and commented majority of the js code to make it easier to understand for those curious on how to make a timer of their own.
+ 2
Use delay(1000);
For C++
library-》process.h
language-》c++
*u can change value to increase time in seconds
+ 1
Why not? It works fine for me. Check my code with multithreading. Playground has an executuon tumeout, so your program should work less then 3 seconds.
+ 1
for the primitive method, you can create a really long for loop
for(int i = 0; i < 1000000; i++){}
the loop does nothing but burning some cpu cycles.
pretty primitive, but works in every language.
0
If you familiar with Java you can use thread and use threads. Sleep() then specify the time you want before second value is displayed
0
how can i insert a delay in ruby?
0
Python: from time import sleep
sleep (3000)
0
how about delay in c++?? I need to know too
0
use sleep function
- 2
use thread