flat assembler
Message board for the users of flat assembler.
Index
> Windows > How do applications know to shutdown? |
Author |
|
asmcoder 02 Sep 2008, 11:57
[content deleted]
Last edited by asmcoder on 14 Aug 2009, 14:56; edited 1 time in total |
|||
02 Sep 2008, 11:57 |
|
vid 02 Sep 2008, 12:38
I think windows just sends WM_CLOSE to apps, and then terminates those which don't respond in time.
|
|||
02 Sep 2008, 12:38 |
|
revolution 02 Sep 2008, 12:53
Windows also sends the WM_ENDSESSION message. An application should process the message if it needs to do any special actions during shutdown.
|
|||
02 Sep 2008, 12:53 |
|
Pinecone_ 14 Sep 2008, 01:01
ok... but what about processes with no message loop? would they just terminate after so many seconds?
|
|||
14 Sep 2008, 01:01 |
|
revolution 14 Sep 2008, 01:54
Apps without message loops and apps that are not responding to the WM_CLOSE message cannot be nicely closed. Windows will wait up to 30 seconds for the app to close, it will also display a window allowing the user to "End Now" without waiting. In either case (the user clicks "End Now" or 30 seconds have passed) Windows will forcibly terminate the process.
|
|||
14 Sep 2008, 01:54 |
|
FrozenKnight 15 Sep 2008, 01:14
The closing of a process quite simple. a process just needs to call the API TerminateProcess. it's the programs responsibility to determine how this happens i usually let windows do it for me by returning from my program to the system where the kernel calls it for me.
As for messages it is usually a good idea to direct WM_CLOSE code that will eventually call TerminateProcess, after you have done all of your cleanup of course. If you want to see this in action try using my little KILL app, I've attached the source. to use this drag from it's the windows grey over any window window and it will die instantly no wait, no saving, no messages. Warning this will kill explorer and the desktop too. I did code an exception so it wont kill it's self. Warning the new version of AntiVir seems to detect this as a virus which is why i didn't include the binary. if you are worried about it then just check the source. Also note that some frozen windows will be treated as though they are the desktop, I personally consider this a flaw in windows as i have done some testing and found that this error is a result of what appears to be a windows bug. I am not responsible for any crashes or data loss due to use of this program. this is a test model and not to be considered a tool. The Icon and Cursor are My art work and you may not use them with out my permission (If you want to use them just ask, I don't intend to be a hard ass about people using them i just want credit if you place them in your app) Anyway in answer to your question, windows just loops through all the process handles and terminates them one at a time. of course it does give them a chance to close first usually a few seconds, you can change that value in the registry to let it wait longer or close faster)
|
|||||||||||
15 Sep 2008, 01:14 |
|
revolution 15 Sep 2008, 01:57
Just to note that calling ExitProcess is preferred to TerminateProcess. The Exit version allows the process to shut down cleanly whereas the Terminate version will abruptly stop the process uncleanly.
|
|||
15 Sep 2008, 01:57 |
|
FrozenKnight 16 Sep 2008, 00:31
from msdn
Quote: If one of the terminated threads in the process holds a lock and the DLL detach code in one of the loaded DLLs attempts to acquire the same lock, then calling ExitProcess results in a deadlock. In contrast, if a process terminates by calling TerminateProcess, the DLLs that the process is attached to are not notified of the process termination. Therefore, if you do not know the state of all threads in your process, it is better to call TerminateProcess than ExitProcess. Note that returning from the main function of an application results in a call to ExitProcess. This is why i use TerminateProcess it's a guaranteed kill, while exit process may be cleaner but it isn't as effective. the truely best result would be to call ExitProcess and if the process still exists one or two seconds later to call TerminateProcess. |
|||
16 Sep 2008, 00:31 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.