Click here to Skip to main content
15,896,915 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys,
I am having some trouble getting a WPF Application to place the host PC into Sleep/Hibernate mode. The below code works in C# but not in the WPF environment.
Application.SetSuspendState(PowerState.Suspend, false, false);

Does anyone know how i could use the above code in WPF? or any other way of placing the host PC into sleep mode?

Thanks for the help in advance,
Alex
Posted

1 solution

Hi Guys,
I managed to get the above code working. It was probably a stupid question and really obvious for everyone on here but i thought i would post the solution anyway just in case.

SetSuspendState is part of the System.Windows.Forms namespace which is not part of the WPF framework.

System.Windows.Forms can be made accessible by following the below steps...

In Solution Explorer, add a reference to the WindowsFormsIntegration assembly, which is named WindowsFormsIntegration.dll.


In Solution Explorer, add a reference to the Windows Forms assembly, which is named System.Windows.Forms.dll.


Then the below code will allow control of the host PC's PowerState.

System.Windows.Forms.Application.SetSuspendState(PowerState.Suspend, false, false);


More information can be found at:
http://msdn.microsoft.com/en-us/library/ms751761.aspx


Alex.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900