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

23rd May 2017, 8:50 PM
Davy Jones 3
Davy Jones 3 - avatar
12 Antworten
+ 3
Thread.sleep(miliseconds); will pause the program entirely. 1000 miliseconds = 1 second.
24th May 2017, 12:27 AM
Rrestoring faith
Rrestoring faith - avatar
+ 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.
23rd May 2017, 9:22 PM
Milan
Milan - avatar
+ 3
Yeah, not sure how it will work out on code playground though. Ps: Thread* not Tread
24th May 2017, 12:30 AM
Rrestoring faith
Rrestoring faith - avatar
+ 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
24th May 2017, 12:34 AM
Rrestoring faith
Rrestoring faith - avatar
+ 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.
23rd May 2017, 9:29 PM
Davy Jones 3
Davy Jones 3 - avatar
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
23rd May 2017, 9:44 PM
Milan
Milan - avatar
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.
23rd May 2017, 10:11 PM
Davy Jones 3
Davy Jones 3 - avatar
0
Actually nevermind that code is in progress and doesn't work.
23rd May 2017, 10:12 PM
Davy Jones 3
Davy Jones 3 - avatar
0
That code has been fixed, now
23rd May 2017, 10:44 PM
Davy Jones 3
Davy Jones 3 - avatar
0
So to create a delay of 5 seconds, Tread.sleep(5000);
24th May 2017, 12:29 AM
Davy Jones 3
Davy Jones 3 - avatar
0
Me neither, but on a regular IDE it would work fine?
24th May 2017, 12:32 AM
Davy Jones 3
Davy Jones 3 - avatar
0
Thanks
24th May 2017, 12:34 AM
Davy Jones 3
Davy Jones 3 - avatar