Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. How to show "Press any key to Continue"

How to show "Press any key to Continue"

Scheduled Pinned Locked Moved C#
visual-studiotutorial
10 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yakupc
    wrote on last edited by
    #1

    Hi, Is there any way to show "Press any key to Continue" message end of the run VS Console application.

    L L V P 4 Replies Last reply
    0
    • Y yakupc

      Hi, Is there any way to show "Press any key to Continue" message end of the run VS Console application.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      yakupc wrote:

      Is there any way to show "Press any key to Continue" message end of the run VS Console application

      Within Visual Studio if you start debugging with Ctrl-F5 it will do it automatically. When you run your program outside this environment you will need to code it yourself (Console.Write and Read).

      V 1 Reply Last reply
      0
      • Y yakupc

        Hi, Is there any way to show "Press any key to Continue" message end of the run VS Console application.

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Console.WriteLine("Press any key to Continue");
        Console.ReadKey();

        the second statement is optional. :laugh:

        Luc Pattyn


        I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


        D 1 Reply Last reply
        0
        • L Lost User

          yakupc wrote:

          Is there any way to show "Press any key to Continue" message end of the run VS Console application

          Within Visual Studio if you start debugging with Ctrl-F5 it will do it automatically. When you run your program outside this environment you will need to code it yourself (Console.Write and Read).

          V Offline
          V Offline
          vtchris peterson
          wrote on last edited by
          #4

          By default, "Ctrl+F5" is mapped to "Start Without Debugging"

          Y 1 Reply Last reply
          0
          • V vtchris peterson

            By default, "Ctrl+F5" is mapped to "Start Without Debugging"

            Y Offline
            Y Offline
            yakupc
            wrote on last edited by
            #5

            worked.It is great.Thank you so much.

            1 Reply Last reply
            0
            • Y yakupc

              Hi, Is there any way to show "Press any key to Continue" message end of the run VS Console application.

              V Offline
              V Offline
              vtchris peterson
              wrote on last edited by
              #6

              Alternate implementation. I actually think the other solution is better, but I was curious if this would work (and it does). Note that UseShellExecute is important, otherwise the process is opened in a new window. The disadvantage is that you're more tightly coupled with the OS (i.e. it wouldn't work under Mono on a non MS-platform)

              using System.Diagnostics;

              // ...

              ProcessStartInfo psi = new ProcessStartInfo("cmd", "/c pause");
              psi.UseShellExecute = false;
              Process.Start(psi).WaitForExit();

              1 Reply Last reply
              0
              • Y yakupc

                Hi, Is there any way to show "Press any key to Continue" message end of the run VS Console application.

                P Offline
                P Offline
                PIEBALDconsult
                wrote on last edited by
                #7

                Or run it from a BAT file.

                myapp.exe
                pause

                L 1 Reply Last reply
                0
                • P PIEBALDconsult

                  Or run it from a BAT file.

                  myapp.exe
                  pause

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #8

                  @echo off :^)

                  Luc Pattyn


                  I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


                  P 1 Reply Last reply
                  0
                  • L Luc Pattyn

                    @echo off :^)

                    Luc Pattyn


                    I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


                    P Offline
                    P Offline
                    PIEBALDconsult
                    wrote on last edited by
                    #9

                    I didn't want to confuse the reader with such details.

                    1 Reply Last reply
                    0
                    • L Luc Pattyn

                      Console.WriteLine("Press any key to Continue");
                      Console.ReadKey();

                      the second statement is optional. :laugh:

                      Luc Pattyn


                      I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


                      D Offline
                      D Offline
                      dojohansen
                      wrote on last edited by
                      #10

                      And a less user-friendly variant:

                      while (true)
                      {
                      Console.WriteLine("Continue to press any key.");
                      Console.ReadKey();
                      }

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups