![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
|
PC shutdown event...?
So I was writing a small app and was wondering what to do if the user presses the power button on their pc whilst the app is still running? I read an article that prevents Standby/Hibernate, but not shutdown...Is it possible to do anything like this in Java?
(Like if I needed to write to a file to save settings and whatnot.)
__________________
Pain is just weakness leaving the body.
|
|
|
|
|
|
#2 |
|
Sexy Programmer
|
The java.util.prefs were introduced in Java 1.4. This package is used to write/read files about your application. Such as saving the window's previous location or the size of the window.
I would recommend, every time a user triggers an event, I would record the information. Here a link to help you get started: http://javaalmanac.com/egs/java.util.prefs/pkg.html
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
|
|
#3 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4
![]() |
Off the top of my head, all of your forms/frames/windows will get the WM_CLOSE message on any logout or shutdown event. The actual shutdown does not occur until all windows close, gracefully or otherwise.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270 |
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Actually, I'm not so sure about that. When I was experimenting with drastic shutdowns at the Win API level, the documentation indicated that I had about 20 ms (a relatively long time if one's process doesn't get swapped out) to wrap it all up. You're probably correct, however, if the adjective "otherwise" indicates that one may be dumped in the landfill before finishing the cleanup.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: May 2006
Location: West Jordan, Utah, United States
Posts: 176
Rep Power: 3
![]() |
Windows will stay open until all of the programs close. I have had it hang and run my battery out on a few occasions because a GDK+ or GDI+ or some kind of window won't close for 6 hours.
|
|
|
|
|
|
#6 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,261
Rep Power: 5
![]() |
Not sure about the java aspects, but the following normally happens after a windows shutdown of logoff is initiated.
1) All windows applications will receive a WM_QUERYENDSESSION message asking for permission to shutdown. An application can indicate, by setting an appropriate flag, that it does want to allow the shutdown/logoff. 2) All windows applications will receive a WM_ENDSESSION message, with a value indicating whether the shutdown is proceeding or not. If shutdown or logoff is occurring, that flag is TRUE. 3) There are a set of similar signals sent to each console process (eg the DOS prompt), to make them shut down as well. I've never developed a console application that needed to respond to a windows shutdown event, so can't give more details. 4) If shutdown is happening, each program is terminated (the sequence of events such as WM_CLOSE for windows applications). This allows the applications to clean up as they terminate (including doing things like prompting a user to save files, which is why a shutdown will not occur while a program waits for user input). The above is what happens in response to a user manually initiates a shutdown or logs off. It can also be initiated programatically with a call to the win32 API functions ExitWindows() or ExitWindowsEx(). ExitWindowsEx() accepts a flag that allows bypassing of the protocol of asking programs for permission to shutdown in emergency situations (it basically shuts down applications with prejudice, and does not allow data to be saved) --- that can't be done manually. Such a technique is one that should be used with extreme caution, as it can make your program unpopular with users. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| MAC remote shutdown tool | Baphomet | Coder's Corner Lounge | 9 | Nov 28th, 2006 9:14 PM |
| School's Out Bash - LAN Event in Ash Flat, Arkansas | bigguy | Coder's Corner Lounge | 21 | Apr 24th, 2006 5:12 PM |
| console event handling | jayme | C++ | 3 | Jan 1st, 2006 3:40 PM |
| question: usage of delagates and custom events | melbolt | C# | 1 | Oct 3rd, 2005 8:17 PM |
| Help! I have a problem | thomas55 | C++ | 1 | Apr 24th, 2005 2:16 PM |