Sameet
Sameet

Reputation: 2211

Saving state before shutting down using .NET

I'd like to save the state of my machine before shutdown (for machines that do not support hibernate).

Essentially, I'm trying to mimic the Windows Hibernate feature. When the machine its turned back on, it looks exactly like it did previous to being shut down.

Any ideas on using managed code to perform this task?

Currently using/considering Windows XP Service Pack 2.

Upvotes: 2

Views: 1146

Answers (3)

Christian.K
Christian.K

Reputation: 49290

Maybe the Vista Application Recovery API does help. Requires Vista though.

Upvotes: 0

Robert Venables
Robert Venables

Reputation: 5981

For all applications running on your computer, this is simply not possible using pure managed code. In fact, even with unmanaged code you will have a hell of a time. I wouldn't say it's impossible but likely extremely difficult and time comsuming.

Here are a few helpful resources to get you started:

Arun Kishan on Windows Kernel
http://www.dotnetrocks.com/default.aspx?ShowNum=434

Core Dump
http://en.wikipedia.org/wiki/Core_dump

setcontext
http://en.wikipedia.org/wiki/Setcontext

Raymond Chen on "Hibernating" single processes
http://blogs.msdn.com/oldnewthing/archive/2004/04/20/116749.aspx

For your own application, your best bet is to isolate all of the state you would like to be able to restore into a set of serializable classes. Then, when your application is unloaded (or periodically), save this data to disk using XMLSerializer. When your application is loaded again, use the XMLSerializer again to rehydrate your classes holding the state of your application and use this information to return the user interface to the previous state. If you have complex user interfaces this could be a time consuming task.

Upvotes: 5

chikak
chikak

Reputation: 1732

you will have to save it yourself before your program exits. you can serialize all windows state to xml and save it in some file. you can reload the settings when your appplication again starts.

Upvotes: 0

Related Questions