exit

How do I make an console application run until the user enters “Q”, “q”, “Quit” or “quit” to terminate it?

时光总嘲笑我的痴心妄想 提交于 2019-12-01 18:55:54
How do I make an console application run until the user enters "Q", "q", "Quit" or "quit" to terminate it? This is my current code: public class Class1 { [STAThread] static void Main(string[] args) { string userName; int i = 0, totalCal = 0, cal = 1; Console.WriteLine("Welcome to the magical calorie counter!"); Console.WriteLine(); Console.Write("Enter in your name -> "); userName = Console.ReadLine(); for (i = 0; i <= 10; i++) { Console.WriteLine("Hello {0}.....Let's add some calories!!", userName); }// end for loop Console.WriteLine(); while (cal != 0) { Console.Write("Enter some Calories:

How to check exit if used tee?

江枫思渺然 提交于 2019-12-01 18:50:45
问题 I try to use tee to save output in file like: myapp | tee log.txt But I have a problem with checking of exit. Previous code: myapp if [ $? -eq 0 ] then ..... But $? will be exit of tee! Does it possible catch exit of myapp? Thanks. 回答1: For bash, there's a convenient special array: PIPESTATUS. The return code for myapp would be in ${PIPESTATUS[0]} and so on. zsh has a roughly identical method. There's also a rather more annoying, hacky way to do it in strict bourne shells that you can read

Java: How to cancel application exit

强颜欢笑 提交于 2019-12-01 17:36:59
On one of my programs, I want a Dialog to appear when the user attempts to exit the application. The user must then choose to save some state of the program, not to save or to cancel the exit operation. I wrote this in an attempt to find a solution first and ony then implement it: import javax.swing.*; import java.awt.Dimension; import java.awt.event.*; class WL implements WindowListener { private boolean statussaved; private JFrame tframe; WL (JFrame frame) { statussaved = false; tframe = frame; } @Override public void windowActivated (WindowEvent w) { } @Override public void windowClosed

atexit, exit delegate in c#

烈酒焚心 提交于 2019-12-01 17:27:27
问题 In c++ there is a function called atexit where you can register functions which should be run when the system exits. Are there any similar events in C#? UPDATE: The AppDomain.ProcessExit doesn't seem to catch Ctrl-C or Ctrl-Break. Anyone knows anything about that? 回答1: You can check the ProcessExit and DomainUnload events of the AppDomain class. 回答2: Maybe the answers to this may help you: How do I trap ctrl-c in a C# console app 回答3: There's the Application.ApplicationExit event if you've a

atexit, exit delegate in c#

送分小仙女□ 提交于 2019-12-01 17:15:51
In c++ there is a function called atexit where you can register functions which should be run when the system exits. Are there any similar events in C#? UPDATE: The AppDomain.ProcessExit doesn't seem to catch Ctrl-C or Ctrl-Break. Anyone knows anything about that? You can check the ProcessExit and DomainUnload events of the AppDomain class. Svish Maybe the answers to this may help you: How do I trap ctrl-c in a C# console app There's the Application.ApplicationExit event if you've a WinForms application. For WPF there's Application.Exit . If you're running a WinForms app you can add a listener

Exit functions in C

落花浮王杯 提交于 2019-12-01 16:21:25
What is the difference between exit() , _exit() and _Exit() in C? How do I decide which to use? On bash, man 2 exit gave me the page _EXIT(2), whereas man 3 exit gave the page EXIT(3). exit() terminating after cleanup. _exit() terminating immediately after call. If you have some stack corrupted while exit() function was called program may close with Segmentation Fault, if you are use _exit() , program exit in quick mode. From http://msdn.microsoft.com/en-us/library/6wdz5232.aspx you have exit() - Performs complete C library termination procedures, terminates the process, and exits with the

Java: How to cancel application exit

亡梦爱人 提交于 2019-12-01 16:15:14
问题 On one of my programs, I want a Dialog to appear when the user attempts to exit the application. The user must then choose to save some state of the program, not to save or to cancel the exit operation. I wrote this in an attempt to find a solution first and ony then implement it: import javax.swing.*; import java.awt.Dimension; import java.awt.event.*; class WL implements WindowListener { private boolean statussaved; private JFrame tframe; WL (JFrame frame) { statussaved = false; tframe =

Exit on application crash

馋奶兔 提交于 2019-12-01 12:43:30
when ever any application crash come I want to exit from the app ? How to achieve same. does Android manifest have any provision for same. I would recommend to register a global UncaughtExceptionHandler . This catches all the exceptions that are not handled. Then you can do there what you want. For example close the app, inform the user and send a log to yourself. You could also use ACRA or a service like BugSense that solve this problem. 来源: https://stackoverflow.com/questions/5193136/exit-on-application-crash

Android application Exit for home screen

≯℡__Kan透↙ 提交于 2019-12-01 11:23:04
I have develop android application,there I have Exit button in menu option.I want exit application and go to home screen when I press exit button. for that I have used following methods 1. System.exit(0) 2. finish() 3. android.os.Process.killProcess(android.os.Process.myPid()) 4. System.runFinalizersOnExit(true); these all methods direct to application my first page not to home screen.so what should I do for this?? please help me Firstly close in an android application is frowned upon because the back button and home button are already kinda giving you this functionality. But if you need to

Android application Exit for home screen

梦想的初衷 提交于 2019-12-01 09:22:43
问题 I have develop android application,there I have Exit button in menu option.I want exit application and go to home screen when I press exit button. for that I have used following methods 1. System.exit(0) 2. finish() 3. android.os.Process.killProcess(android.os.Process.myPid()) 4. System.runFinalizersOnExit(true); these all methods direct to application my first page not to home screen.so what should I do for this?? please help me 回答1: Firstly close in an android application is frowned upon