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,
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.
Read the question carefully.
Understand that English isn't everyone's first language so be lenient of bad
spelling and grammar.
If a question is poorly phrased then either ask for clarification, ignore it, or
edit the question
and fix the problem. Insults are not welcome.
Don't tell someone to read the manual. Chances are they have and don't get it.
Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.