Sign in to follow this  

question 1 of 356,000

This topic is 4225 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, I have a problem. I am trying to switch over from C++ to C#...and i dont know what is going on. Im taking it one step at a time. First question: How do I pause the screen? In C++ it is simply " system("pause"); "...

Share this post


Link to post
Share on other sites
Hmm, ok --

First of all, why would you want to 'pause' the screen in this way? To see output? If so, you can always run your console app through the terminal (go into Run, type cmd and navigate to the appropriate directory....)

However, if you really want to 'pause', you could always do the equivalent of a cin call... Console.ReadLine(); ...or some other equivalent. Personally I don't like the idea of artificially stalling the execution of your program like this. There's a number of other ways to get output etc so I guess the final word is consider why you're doing this in the first place?

[EDIT] Just for references sake, MSDN uses Console.ReadLine() -- check out this on the MSDN and see how they end their program. Just because MS shows you the way doesn't mean it's a good idea though ;)


~Shiny.


[Edited by - Shiny on April 30, 2006 2:51:49 AM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You have to pinvoke this C function into your C# application. Luckily, this process is very easy. There are a few steps:

1) Insert System.Runtime.InteropServices to your using clauses.
2) Insert this line in your class (usually in the first few lines)

[DllImport("msvcrt.dll")]
static extern bool system(string str);

3) In that same class, simply write this:
system("pause");

Hope that helps!

Share this post


Link to post
Share on other sites
This is absurd.

System("PAUSE") is a nasty and unnecessary icky. C# for console now like the new? Run from console, console stays and no closure.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Are you afraid of a few milliseconds loss in a console application? Are you afraid of portability loss when you're obviously targeting the Windows operating system with C#? For my apps, Console.ReadLine() does enough for a quick solution.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
Are you afraid of a few milliseconds loss in a console application? Are you afraid of portability loss when you're obviously targeting the Windows operating system with C#? For my apps, Console.ReadLine() does enough for a quick solution.


Are you afraid of logging in?

[edit] And by the way, the "right" way of going about it (if you're too lazy to open up a console window), is to go to Debug->Start Without Debugging.


jfl.

Share this post


Link to post
Share on other sites
Quote:
Original post by jflanglois
Quote:
Original post by Anonymous Poster
Are you afraid of a few milliseconds loss in a console application? Are you afraid of portability loss when you're obviously targeting the Windows operating system with C#? For my apps, Console.ReadLine() does enough for a quick solution.


Are you afraid of logging in?

[edit] And by the way, the "right" way of going about it (if you're too lazy to open up a console window), is to go to Debug->Start Without Debugging.


jfl.


nice... lol.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You guys need to focus more on giving answers to peoples questions, regardless of personal opinion on the subject. That's ll I've ever known from the folks at GameDev. I don't believe a username is required for a perfectly valid answer, and sadly you don't study regardless of possible "off the shelf" solutions.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Btw, you just rate people down when they give a valid answer, so why bother at all? :)

jflanglois, I have a few problems with that solution. 1) Your user won't get to press a key at the end. The program exits for you. You can test this yourself by going into your release folder and execute your program. Thus, the user has an abrupt exit. A better solution for pausing is needed. My solution works. 2) The user's program may need to be put on pause throughout the application. My solution works. 3) You shouldn't test the user's experience by running your exe in the IDE, regardless if you run without debugging.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
You guys need to focus more on giving answers to peoples questions, regardless of personal opinion on the subject.


I at least like to focus on answering *problems*. A person who already knew exactly what to ask would be able to find the solution for him/herself via Google; when a beginner posts on a forum, it's because at least some amount of confusion factors in to the situation. It's entirely likely that the beginner has the wrong approach or expectations.

Artificially pausing a program at the end via system("pause") is a bad *idea* for a few reasons: it interferes with batch runs; the support has to be compiled in (when you could instead use a batch file to call your program, and then the pause program); it relies on the program being there (and being named what you expect, and doing what you expect it to...); it may interact oddly from a user interface perspective with the existing menu system (e.g. if there's already a "quit" option). Many of these problems exist independant of how you implement the pause within your program. And all of this is just to work around the fact that you're not "running the app properly" in the first place. A console app is designed to be launched from within an existing console window. Your IDE, if you use one, ought to do that for you already, or at least (provide an option to) put in the pause call itself.

Share this post


Link to post
Share on other sites

This topic is 4225 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this