Title: Suspend or hibernate the system in C#
The Application.SetSuspendState method lets an application make the system suspend or hibernate. A suspended system enters a low power mode. A hibernating system saves its memory contents to disk and then enters low power mode.
Because it doesn't need to restore the saved memory, a suspended system can resume more quickly than a hibernating system. However, if the computer loses power while suspended, running programs are not properly restored.
The following code lets the program suspend or hibernate the system.
// Suspend.
private void btnSuspend_Click(object sender, EventArgs e)
{
Application.SetSuspendState(PowerState.Suspend, false, false);
}
// Hibernate.
private void btnHibernate_Click(object sender, EventArgs e)
{
Application.SetSuspendState(PowerState.Hibernate, false, false);
}
For more information about the SetSuspendState method, see Application.SetSuspendState Method.
Download the example to experiment with it and to see additional details.
|