0
How can I create a delay
When I write a code I use a WriteLine to ask (the user) a question but before it does that, the ReadLine has already asked for input. How can I delay the ReadLine
12 Respuestas
+ 3
Thread.sleep(miliseconds);
will pause the program entirely.
1000 miliseconds = 1 second.
+ 3
WriteLine asks a question, but you need ReadLine for input. User can not give input after WriteLine, only after ReadLine (which is only seen in the code). In other words, you don't really need delay. And I think that ReadLine goes after WriteLine.
+ 3
Yeah, not sure how it will work out on code playground though.
Ps: Thread* not Tread
+ 3
Yes. Just keep in mind Thread.sleep pauses everything. So you cannot do other tasks while this is executed.
There might be some info here on how to pause it while doing tasks: (2nd top answer)
https://stackoverflow.com/questions/5449956/how-to-add-a-delay-for-a-2-or-3-seconds
+ 2
Your right about WriteLine going before ReadLine, but that's why I need a delay. This app's "Code Playground" asks for input for the ReadLine before showing what was the result of the WriteLine.
0
How can that be?
You write:
string name;
Console.WriteLine ("What is your name?");
name=Console.ReadLine ();
Console.WriteLine("Your name is: {0}", name);
Console.ReadKey();
when you run it, it should output:
What is your name?
Your name is: Milan
0
Check out my code Name Calculator, it will ask for input before showing the Console.WriteLine, which asks the question in the first place.
0
Actually nevermind that code is in progress and doesn't work.
0
That code has been fixed, now
0
So to create a delay of 5 seconds, Tread.sleep(5000);
0
Me neither, but on a regular IDE it would work fine?
0
Thanks