exit

C++: execute a while loop until a key is pressed e.g. Esc?

大憨熊 提交于 2019-11-29 14:27:39
问题 Does anyone have a snippet of code that doesn't use windows.h to check for a key press within a while loop. Basically this code but without having to use windows.h to do it. I want to use it on Linux and Windows. #include <windows.h> #include <iostream> int main() { bool exit = false; while(exit == false) { if (GetAsyncKeyState(VK_ESCAPE)) { exit = true; } std::cout<<"press esc to exit! "<<std::endl; } std::cout<<"exited: "<<std::endl; return 0; } 回答1: Your best bet is to create a custom

difference between view exit and view destroy

好久不见. 提交于 2019-11-29 13:32:12
Created by Wang, Jerry, last modified on Nov 08, 2015 Control.prototype.destroy _cleanupBusyIndicator(); sap.ui.core.ResizeHandler.deregisterAllForControl this._busyIndicatorDelayedCallId q.sap.clearDelayedCall this._busyAnimationTimer1 clearTimeout(this._busyAnimationTimer1); bSuppressInvalidate if true, the UI element is not marked for redraw ManagedObject.prototype.destroy.call(this, bSuppressInvalidate); this.$().remove(); // remove this control from DOM, e.g. if there is no parent Inside view.destroy, it will call this.exit if this.exit exists. in control.prototype.exit, this

batch script if user press Ctrl+C do a command before exiting

回眸只為那壹抹淺笑 提交于 2019-11-29 10:23:43
I wrote a script which is doing net use at the beginning and net use /DELETE at the end. But if user decides to press Ctrl + C and exits the script, I need to do a net use /DELETE . Is that possible? I can't find anything on google. Sure, simply execute most of your script in a new CMD session: @echo off if "%~1" neq "_start_" ( net use ... cmd /c "%~f0" _start_ %* net use /delete ... exit /b ) shift /1 REM rest of script goes here As long as your console window remains open, the net use /delete command will always fire after the inner cmd session closes. It could close because of normal run,

How do I properly close a winforms application in C#?

坚强是说给别人听的谎言 提交于 2019-11-29 09:27:27
I ran the .exe for my program from the debug folder. It worked, but when I closed it, I discovered that it was still listed on the processes list in the Task Manager. I figure I must've forgotten a step, since it's my first winforms program. As long as the code in your Main method looks like this: Application.Run(new MainForm()); Then you should be OK (assuming "MainForm" is the name of your main form). WinForms will exit the process when the form you pass in to Application.Run closes. Otherwise you can call Application.Exit() yourself in your form's "Closed" event handler. 来源: https:/

How to make Java program exit after a couple of seconds

北城以北 提交于 2019-11-29 08:11:00
Is there anyway I can exit a java program after a couple of seconds e.g. 5 seconds. I know you can quit the java program using: System.exit(0); But I'm not sure whether the 0 stands for seconds since this code: System.exit(10); also exits instantly System.exit(0) specifies the exit error code of the program. you can put it on a timer and schedule the task import java.util.Date; import java.util.Timer; import java.util.TimerTask; public class TimedExit { Timer timer = new Timer(); TimerTask exitApp = new TimerTask() { public void run() { System.exit(0); } }; public TimedExit() { timer.schedule

Android App Exit Button

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 07:07:45
I'm not sure whether I need to add an exit button to my app. Is there any point to doing this? And if on exiting one activity or service is not .finish() or closed properly could this cause a lot of damage? You don't need to add en exit button. If you don't, your activity will just be kept in memory until the system reclaims it. It will not consume any cpu. Of course, if you have any worker threads running you should stop them in onStop() or onPause(), depending on what your threads are doing. Many applications add an exit button, for some reason. I guess the reason is that they don't trust

How to run one last function before getting killed in Python?

霸气de小男生 提交于 2019-11-29 06:22:34
问题 Is there any way to run one last command before a running Python script is stopped by being killed by some other script, keyboard interrupt etc. 回答1: import time try: time.sleep(10) finally: print "clean up" clean up Traceback (most recent call last): File "<stdin>", line 2, in <module> KeyboardInterrupt If you need to catch other OS level interrupts, look at the signal module: http://docs.python.org/library/signal.html Signal Example from signal import * import sys, time def clean(*args):

Handle a WPF Exit Event

狂风中的少年 提交于 2019-11-29 05:45:44
I was wondering if there was a way to handle a WPF Application Exit event such that the exit was cancelled. The use case is that I have a client-server situation where the server is a WPF app. I want the WPF app to notify the client when it is shutting down, but cancel the shutdown process. The client should receive the shutdown notification, do its own required cleanup and then ask the WPF app to shutdown via a request. Is this possible? You can hook the event Closing on your main window like this - <Window Closing="Window_Closing"> And in your event set the e.Cancel to true to stop the

python sys.exit not working in try [duplicate]

眉间皱痕 提交于 2019-11-29 03:27:33
This question already has an answer here: Why is “except: pass” a bad programming practice? 16 answers Python 2.7.5 (default, Feb 26 2014, 13:43:17) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> try: ... sys.exit() ... except: ... print "in except" ... in except >>> try: ... sys.exit(0) ... except: ... print "in except" ... in except >>> try: ... sys.exit(1) ... except: ... print "in except" ... in except Why am not able to trigger sys.exit() in try, any suggestions...!!! The code posted here has all

OnExit Event For a Swing Application?

丶灬走出姿态 提交于 2019-11-29 01:27:23
I'm developing a simple application to manage the operational part of a business using Swing, but I need that when the application exits, it performs this: updateZonas(); db.close(); But how can I do this? Santhosh Kumar Tekuri Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { updateZonas(); db.close(); } }); This works for any Java application(Swing/AWT/Console) Are you using a JFrame? if so you can try this: myframe.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(WindowEvent winEvt) { updateZonas(); db.close(); System.exit(0);