formclosing

Get the application closing event

淺唱寂寞╮ 提交于 2019-11-27 14:50:30
问题 How to get to the application closing event? I want to get application to save all unsaved operations or show the user a message "Are you sure about closing without saving all data?" something like this. If this will be helpful - the application is a SingleFrameAplication using Swing. 回答1: You could use a shutdown hook. It works for Swing, AWT and even console applications. Example: Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { //do your stuff } }); 回答2:

Detecting when a Java application closes

假如想象 提交于 2019-11-27 08:37:54
问题 I am trying to detect when the Java application is about to close so I can perform methods to release resources, I have done it in C# as follows: //Intercept when the application closes private void Form1_FormClosing(object sender, FormClosingEventArgs e) { //Reclaim resources from MIDI usage if (MIDIControl.CleanUp()) { Logger.Add("Closed resources successfully on Form Close \n"); } else { Logger.Add("Failed to close all resources on Form Close."); } } I've tried to perform the same

Awaiting Asynchronous function inside FormClosing Event

a 夏天 提交于 2019-11-27 04:58:22
I'm having a problem where I cannot await an asynchronous function inside of the FormClosing event which will determine whether the form close should continue. I have created a simple example that prompts you to save unsaved changes if you close without saving (much like with notepad or microsoft word). The problem I ran into is that when I await the asynchronous Save function, it proceeds to close the form before the save function has completed, then it comes back to the closing function when it is done and tries to continue. My only solution is to cancel the closing event before calling

Window close events in a winforms application

浪尽此生 提交于 2019-11-27 04:48:18
问题 I am looking to prompt the user to save data when they close a form window in a winforms application. I can't figure out how to trigger the prompt to the user, should they click the red box at the top right corner of the form. My application currently has a boolean flag, that is set to True on textchanged event. So I will only need to check for the boolean value in whatever event is trigger by the red box. Any advice? 回答1: You need to handle the FormClosing event. This event is raised just

How can I prevent a user from closing my C# application?

房东的猫 提交于 2019-11-27 04:34:33
How to make unclosed application in C#? I want to disable the 'X' button of the form and prevent the Windows Task Manager from closing it as well. I know that one way to prevent a form from closing is to handle the FormClosing event, but how do I prevent the task manager from closing it? Cody Gray No, it is not possible to prevent Task Manager from closing your application. Task Manager can forcibly terminate a process that is not responding; it doesn't need the application's permission to close it, and it doesn't ask nicely, either. (See this answer for more on Task Manager, and a comparison

How can I prevent a user from closing my C# application?

痴心易碎 提交于 2019-11-26 12:45:13
问题 How to make unclosed application in C#? I want to disable the \'X\' button of the form and prevent the Windows Task Manager from closing it as well. I know that one way to prevent a form from closing is to handle the FormClosing event, but how do I prevent the task manager from closing it? 回答1: No, it is not possible to prevent Task Manager from closing your application. Task Manager can forcibly terminate a process that is not responding; it doesn't need the application's permission to close