How to make timer/delay? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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)

3rd Nov 2016, 1:35 PM
Wen Qin
Wen Qin - avatar
15 Answers
+ 5
Ok thanks. Now I figured out the problem. SoloLearn programme doesn't fully support Thread.Sleep programe
4th Nov 2016, 3:01 AM
Wen Qin
Wen Qin - avatar
+ 14
using System.Threading; Thread.Sleep(interval);
3rd Nov 2016, 7:34 PM
Юрий Алчинов
Юрий Алчинов - avatar
+ 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! "); } } }
10th Nov 2016, 3:04 AM
Md Mizanur Rahman
Md Mizanur Rahman - avatar
+ 4
Note that the interval is in milliseconds
4th Nov 2016, 2:35 AM
Antoan
Antoan - avatar
+ 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
4th Nov 2016, 9:17 AM
Wen Qin
Wen Qin - avatar
+ 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.
8th Nov 2016, 5:39 PM
Lux
Lux - avatar
+ 2
Use delay(1000); For C++ library-》process.h language-》c++ *u can change value to increase time in seconds
1st Jan 2017, 11:09 AM
Priyansh
Priyansh - avatar
+ 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.
4th Nov 2016, 8:39 AM
Юрий Алчинов
Юрий Алчинов - avatar
+ 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.
1st Jan 2017, 4:19 AM
Shahar Levy
Shahar Levy - avatar
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
6th Nov 2016, 10:07 AM
Niclause
Niclause - avatar
0
how can i insert a delay in ruby?
10th Nov 2016, 6:32 AM
Etabeta1🇮🇹
Etabeta1🇮🇹 - avatar
0
Python: from time import sleep sleep (3000)
1st Jan 2017, 10:15 AM
Carmelo Cellupica
0
how about delay in c++?? I need to know too
1st Jan 2017, 10:43 AM
Fluffy Rabbit
Fluffy Rabbit - avatar
0
use sleep function
1st Jan 2017, 11:33 AM
kiya
kiya - avatar
- 2
use thread
3rd Nov 2016, 6:01 PM
striker s
striker s - avatar