How to add time or loading time to console.

orav123

New member
Joined
May 21, 2013
Messages
2
Programming Experience
1-3
Hey made a simple console.writeline code i added like 5 of them but is there any way to but them in lag or something if i start it everything comes up in the console in one second and console dissapears whitout msgbox is there any way that there is like console.writeline Then it loads forl ike 5 seconds and then comes up the next one and acctually stays there like the console.
 
Actually, Thread.Sleep() wouldn't be a very good solution here. That method is not intended to be used as a delay or a way of measuring when the next piece of code should fire. It's an easy solution, but not exactly a proper one.
 
Actually, Thread.Sleep() wouldn't be a very good solution here. That method is not intended to be used as a delay or a way of measuring when the next piece of code should fire. It's an easy solution, but not exactly a proper one.
What do you suggest? Keep in mind this is a Console Application.
 
Use the System.Threading.Timer class: Timer Class (System.Threading)

:scatter:
I disagree with you on that. In pseudo code this is what should happen:
console.writeline
wait one second
console.writeline
wait one second
exit
If you wanted to avoid Thread.Sleep it would make whole lot more sense to use a ManualResetEvent and call WaitOne(1000) instead of Sleep(1000).
 
I disagree with you on that. In pseudo code this is what should happen:

If you wanted to avoid Thread.Sleep it would make whole lot more sense to use a ManualResetEvent and call WaitOne(1000) instead of Sleep(1000).

console.writeline
wait one second
console.writeline
wait one second
exit

That is the problem. "wait one second" -- You can't guarantee that Thread.Sleep(1000) will wait one second. Read this: Thread.Sleep is a sign of a poorly designed program. - Peter Ritchie's MVP Blog

If you want it would be okay to use the ManualResetEvent class however.

Regards,
Ace
 
The simplest thing to do is add
Console.ReadLine()
at the end of your program, and between each of the lines you want to display. It's a pause that will wait for the user to press the Enter key before continuing with the next line.
 
WaitOne()?

JohnH: How would you use the ManualResetEvent with WaitOne in a Console application? I tried this but it doesn't work:

VB.NET:
Imports System.Threading.ManualResetEvent
Module Module1

    Sub Main()
        Console.WriteLine("One")
        WaitOne(1000)
        Console.WriteLine("Two")
        Console.ReadLine()
    End Sub

End Module
 
JohnH: How would you use the ManualResetEvent with WaitOne in a Console application? I tried this but it doesn't work:
You must be having a real off-day... :) ManualResetEvent is a class and WaitOne is an instance method, so you create an instance using New keyword and call its method.
        Dim m As New Threading.ManualResetEvent(False)
        Console.WriteLine("one")
        m.WaitOne(1000)
 
Back
Top