Results 1 to 12 of 12

Thread: How to add time or loading time to console.

  1. #1
    orav123 is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.5
    Join Date
    May 2013
    Posts
    2
    Reputation
    0

    How to add time or loading time to console.

    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.

  2. #2
    JohnH's Avatar
    JohnH is online now VB.NET Forum Moderator
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    15,085
    Reputation
    2803

  3. #3
    orav123 is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.5
    Join Date
    May 2013
    Posts
    2
    Reputation
    0
    Thank you !

  4. #4
    AceInfinity's Avatar
    AceInfinity is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2012
    Posts
    32
    Reputation
    55
    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.

    (.NET Programming MVP - 2012 - Present)
    Crestron DMC-T Certified Programmer


  5. #5
    JohnH's Avatar
    JohnH is online now VB.NET Forum Moderator
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    15,085
    Reputation
    2803
    Quote Originally Posted by AceInfinity View Post
    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.
    How to format posts with code blocks etc - present the problem/post properly

    Visual Studio Community 2017

  6. #6
    AceInfinity's Avatar
    AceInfinity is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2012
    Posts
    32
    Reputation
    55
    Use the System.Threading.Timer class: Timer Class (System.Threading)


    (.NET Programming MVP - 2012 - Present)
    Crestron DMC-T Certified Programmer


  7. #7
    JohnH's Avatar
    JohnH is online now VB.NET Forum Moderator
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    15,085
    Reputation
    2803
    Quote Originally Posted by AceInfinity View Post
    Use the System.Threading.Timer class: Timer Class (System.Threading)

    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).
    How to format posts with code blocks etc - present the problem/post properly

    Visual Studio Community 2017

  8. #8
    AceInfinity's Avatar
    AceInfinity is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2012
    Posts
    32
    Reputation
    55
    Quote Originally Posted by JohnH View Post
    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

    (.NET Programming MVP - 2012 - Present)
    Crestron DMC-T Certified Programmer


  9. #9
    Solitaire is offline VB.NET Forum Miyagee
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2004
    Location
    New York
    Posts
    465
    Reputation
    210
    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.

  10. #10
    Solitaire is offline VB.NET Forum Miyagee
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2004
    Location
    New York
    Posts
    465
    Reputation
    210

    WaitOne()?

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

    Code:
    Imports System.Threading.ManualResetEvent
    Module Module1
    
        Sub Main()
            Console.WriteLine("One")
            WaitOne(1000)
            Console.WriteLine("Two")
            Console.ReadLine()
        End Sub
    
    End Module

  11. #11
    JohnH's Avatar
    JohnH is online now VB.NET Forum Moderator
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    15,085
    Reputation
    2803
    Quote Originally Posted by Solitaire View Post
    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)
    How to format posts with code blocks etc - present the problem/post properly

    Visual Studio Community 2017

  12. #12
    Solitaire is offline VB.NET Forum Miyagee
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2004
    Location
    New York
    Posts
    465
    Reputation
    210
    Thank you. I worked it out right after posting, very similar to what you did.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •