Random Post: Design by Contract Part 2
RSS .92| RSS 2.0| ATOM 0.3
  • Home
  • About
  • Eric’s Toolset
  • Free Software
  • Software License
  •  

    Sleep Mode from .NET

    August 29th, 2007 by Eric

    I have a little backup program that I wrote that includes the ability to shut down the machine when a backup is complete. I wanted to add the option of putting the machine to sleep instead of shutting down, but it took me a while to figure out how to accomplish this.

    After using WMI to implement the shut down code,  I thought it might be an equally painful process to enter sleep mode. Once found, however, the solution is very simple: See System.Windows.Forms.Application.SetSuspendState.

    For example:

    Application.SetSuspendState(PowerState.Suspend, true, false);

     I guess my problem was that I was Googling for the user-centric term “sleep” instead of searching for “suspend”, and if you throw “sleep” and “C#” into a search, you tend to get a lot of threading results.

    Leave a Reply