application-shutdown

How to call event before Environment.Exit()?

馋奶兔 提交于 2019-12-10 12:48:20
问题 I have a console application in C#. If something goes wrong, I call Environment.Exit() to close my application. I need to disconnect from the server and close some files before the application ends. In Java, I can implement a shutdown hook and register it via Runtime.getRuntime().addShutdownHook() . How can I achieve the same in C#? 回答1: You can attach an event handler to the current application domain's ProcessExit event: using System; class Program { static void Main(string[] args) {

How to turn off pc via windows API?

柔情痞子 提交于 2019-12-09 00:09:25
问题 I never programmed a winapi so i have a little problem here . I need turn off my pc from my application . I found this example link text then i found this example how to change privileges link text But i have problem how to get that parameter HANDLE hToken // access token handle I think i need to make it in the next order to get the parameter OpenProcessToken LookupPrivilegeValue AdjustTokenPrivileges but there are a lot parameters that i have no idea what to do with them . maybe you have

Is there something like finally() in Go just opposite to what init()?

守給你的承諾、 提交于 2019-12-07 02:32:29
问题 Is there something in Go which do just opposite to what init() do inside a package? 回答1: This was discussed before by the Go team, and the conclusion was not to add support for it. Quoting minux: Personally, I prefer the style where program exit is handled exactly same as program crash. I believe no matter how hard you try, your program can still crash under some unforeseen situations; for example, memory shortage can bring any well-behave Go program to a crash, and there is nothing you can

How to implement thread pool that will automatically shutdown at end of execution?

安稳与你 提交于 2019-12-06 07:55:25
I'm writing a Java client which could theoretically be used in a different environment: Java main(), in a servlet container, or via dependency injection. The client implements internal connection thread pooling. The problem with this approach is that users of the client that are unaware of the fact that an internal thread pool is implemented will see his or her application "hang" on shutdown. My users need to know to send a shutdown() message to the library. I'm wondering if any other alternative approach could be taken that would, on one hand, allow me to start a thread pool for my

Is there something like finally() in Go just opposite to what init()?

岁酱吖の 提交于 2019-12-05 04:55:10
Is there something in Go which do just opposite to what init() do inside a package? icza This was discussed before by the Go team, and the conclusion was not to add support for it. Quoting minux : Personally, I prefer the style where program exit is handled exactly same as program crash. I believe no matter how hard you try, your program can still crash under some unforeseen situations; for example, memory shortage can bring any well-behave Go program to a crash, and there is nothing you can do about it; so it's better to design for them. If you follow this, you won't feel the need for atexit

Intercepting java machine shutdown call?

强颜欢笑 提交于 2019-12-04 03:40:56
问题 Is there any way to get notified of JVM shutting down or System.exit call before the actual shutdown? I want this, so my application will be able to make a clean exit. I realize that such thing is unlikely to exist, but still, maybe there is something like this? 回答1: Have a look at Runtime.addShutdownHook From the API docs: The Java virtual machine shuts down in response to two kinds of events: The program exits normally, when the last non-daemon thread exits or when the exit (equivalently,

How to debug a crash that only occurs on application shutdown? (Delphi)

删除回忆录丶 提交于 2019-12-03 12:00:41
So, after some recent changes we discovered that one of our oldest applications is sometimes crashing on shutdown. This manifests itself either in the form of "Runtime error 216" messages or in a message from Windows Error Reporting that the application has stopped working. The application is already emitting OutputDebugString -messages at every turn and AFAICT all of our own code gets executed correctly to completion. All destructors are called as are all finalization sections and class destructors, none of which are raising any exceptions. Also, neither madExcept nor FastMM4's Full Debug

Shutdown exception handling for Win32/C++

回眸只為那壹抹淺笑 提交于 2019-12-02 03:18:13
I have a process that handles exceptions great. It calls: _set_se_translator(exception_trans_func); SetUnhandledExceptionFilter(UnhandledExceptionFilterHandler); _set_purecall_handler(purecallHandler); set_terminate(terminateHandler); set_unexpected(unexpectedHandler); _set_invalid_parameter_handler(InvalidParameterHandler); atexit(exitHandler); //ignored during an expected exit _onexit(onexitHandler); //ignored during an expected exit Anytime an exception happens, one of the handlers is called which creates a crash dump for me. Life is good. Except at one customer site. When they shutdown the

Prompt user to save when closing app

丶灬走出姿态 提交于 2019-12-01 05:44:30
I'm writing what boils down to a document editor. When the application is closing, I need to prompt the user to save changes. This is easy enough. My question is when is it appropriate to not prompt the user, and instead simply discard unsaved data and close. In the FormClosing event, the CloseReason enum includes: None WindowsShutDown MdiFormClosing UserClosing TaskManagerClosing FormOwnerClosing ApplicationExitCall I figure that WindowsShutDown and TaskManagerClosing should not cause a "save changes?" prompt to appear, to prevent the app from hanging with that prompt showing. Is this

Prompt user to save when closing app

倾然丶 夕夏残阳落幕 提交于 2019-12-01 03:28:41
问题 I'm writing what boils down to a document editor. When the application is closing, I need to prompt the user to save changes. This is easy enough. My question is when is it appropriate to not prompt the user, and instead simply discard unsaved data and close. In the FormClosing event, the CloseReason enum includes: None WindowsShutDown MdiFormClosing UserClosing TaskManagerClosing FormOwnerClosing ApplicationExitCall I figure that WindowsShutDown and TaskManagerClosing should not cause a