Make the computer suspend or hibernate in C#

The Application.SetSuspendState 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 saves memory, a suspended system can resume more quickly than a hibernating system. However, if the computer loses power while suspended, the programs are not properly restored.

The following code shows how the example program suspends or hibernates 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.

   

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this post.
Comments
  • No comments exist for this post.
Leave a comment

Submitted comments are subject to moderation before being displayed.

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.