On Wednesday 11 September 2002 10:07 am, Andreas Raab wrote:
Ned,
What about the WM_POWERBROADCAST message (at least for non-WinCE apps)?
You missed my point entirely or perhaps I didn't make it clear enough. Of course there are ways of getting notified (there always are) in the VM about a startup but what should the VM do?! It doesn't know enough about the resources associated (like, for example, what files are open and where the files come from) nor does it know about how to handle this situation in the context of some application or other. E.g., even assuming that we'd be enumerating the entire object memory to find all the file handles, do we actually know which ones to reopen?! Do we know how to handle failure situations?! Do we know if it's appropriate to reopen a network connection or not?! At the VM level, we just don't. And that's the problem. So the best I could eventually do is to pass some notification up to the Squeak level. But even then it's not always clear how to handle the situation. It would be much simpler if you could rely on the OS to handle these things for you if it pulls away the carpet under your feets ;-)
I agree that the OS shouldn't change the state of the system when the power comes back up, if it can manage not to. But Squeak _could_ be more power-aware, especially for PDAs.
We're in a position in the VM to actually remember sockets and file handles.
We can hear that the power's going down from the OS and refuse to power down if we have a network file share open that isn't cached locally.
We can hear that the power came back up and we need to repaint the window.
We can notify the OS that we're actually busy when we are doing something so it doesn't power us down.
We could close sockets and remote file handles on power-down. We're already detecting attempted operations on closed handles and raising exceptions. We could if we wanted, remember that we closed the files because of power-down.
As you point out, handling such errors is the concern of the application, but we could at least raise a recognizable exception to let the application know what happened: i.e. the difference between "tried to read from a file that was already intentionally closed (software error)" and "tried to read from a file that was closed on power down (not a software error)".
There are guidelines here for dealing with power management in Win2K: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnhdware/ht...