Suspend or hibernate the system in C#

[hibernate]

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 Example   Follow me on Twitter   RSS feed   Donate




This entry was posted in system and tagged , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *