Avoid standby under vista with c# ?

V

Volkan Senguel

Hi i'm searching a solution to avoid that the user can go in the standby
mode while a app is runing.

i have searched and readed a lot in the web and have not found a working
solution...
for the moment i use "away mode" under vista to get simiar results but with
other handycaps like screen off etc. :-(


i have get this code from a other dev but it doesnt work with vista, the pc
its going directly in the standby mode.

------------------------------------------
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace MonitorSleepPrevent
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern EXECUTION_STATE SetThreadExecutionState(
EXECUTION_STATE flags);

[Flags]
public enum EXECUTION_STATE : uint
{
ES_SYSTEM_REQUIRED = 0x00000001,
ES_DISPLAY_REQUIRED = 0x00000002,
// ES_USER_PRESENT = 0x00000004,
ES_CONTINUOUS = 0x80000000
}

void PreventMonitorPowerdown()
{
SetThreadExecutionState( EXECUTION_STATE.ES_DISPLAY_REQUIRED |
EXECUTION_STATE.ES_CONTINUOUS);
}

void AllowMonitorPowerdown()
{
SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS);
}

private void Form1_Load(object sender, EventArgs e)
{
PreventMonitorPowerdown();
}
}
}
------------------------------------------

please help me to get a working solution for that

what i need is:

if the app is running and the user is pressing the power button (standby) or
uses the start\shutdown(standby) menu the pc should still on.

thank you for any tips
Volkan
 
V

Volkan von Klass

Sure i know that, but in Windows XP was possible to avoid the standby mode
by a application so that the user can not force the standby... only shutdown
etc...

Under Vista does this not work because Vista doesnt broadcast the suspend
message anymore, and by changing the SetThreadExecutionState does not work
:-(

Infos from Microsoft:
http://download.microsoft.com/downl...dc_2005_developingpower-awareapplications.ppt

Windows Vista will not query user mode components when entering sleep
PBT_APMQUERYSUSPEND event will not be sent

Windows Vista will continue to notify user mode components when entering
sleep
PBT_APMSUSPEND event is sent
Timeout has been reduced from 20s to 2s
Use this event to do limited cleanup before the suspend transition


Realy i dont know how to handle this because we have a multimedia app which
works flawless under xp, users can record and not go into standby while
reording is in progress.
Under Vista, user goes to standby and the recording are lost (!)

thats the reason why i need a working solution for that.

thank you
Volkan


Peter Duniho said:
[...]
if the app is running and the user is pressing the power button
(standby) or
uses the start\shutdown(standby) menu the pc should still on.

I'm not convinced you can do this. The OS provides ways for an
application to tell it not to go into standby/hibernate/screen-saver
automatically. But if the user explicitly commands that, I don't think
there's much you can do about that. Ultimately, the OS needs to respect
the user's wishes.

Pete
 
C

christery

Heh, dont eaven know what that is..
PBT_APMSUSPEND event is sent
Timeout has been reduced from 20s to 2s
Use this event to do limited cleanup before the suspend transition

Just a thought, why not send a keystroke from the program, "left/right
shift pressed" to avoid that (watch out for KVM:s timeout) ... a timer
and ... voila...

Or, too stupid approach? I use KISS, so Keep It Simple Stupid ;) so
dont use it.

//CY
 
J

Joerg

Peter Duniho said:
Sure i know that, but in Windows XP was possible to avoid the standby
mode by a application so that the user can not force the standby... only
shutdown etc...

[...]

Realy i dont know how to handle this because we have a multimedia app
which works flawless under xp, users can record and not go into standby
while reording is in progress.
Under Vista, user goes to standby and the recording are lost (!)

I really don't understand what you're saying.

If you mean that Vista itself is automatically trying to go into standby
mode, and you're unable to prevent that, then yes...I agree there should
be an API in the OS that allows that, and frankly the existing one that
works in XP ought to work in Vista too.

But if you mean that you can in XP prevent the system from going into
standby even when the user has explicitly told it to, and that you're
disappointed that that no longer works in Vista, well... My opinion is
that the XP behavior was a bug, and I'm happy to hear they fixed it in
Vista.

If the latter scenario is what you're talking about, the solution is to
tell your users to stop putting the system into standby mode when they are
trying to use the computer record.

If the former, I would report it as a bug against Vista
(http://connect.microsoft.com/), as well as contact Microsoft through
their support web site (http://support.microsoft.com/) and file a support
request against Vista. I have found that on occasion, filing a support
request results in a confirmation of the bug as well as help to work
around the problem.

Pete

I came across searching for a solution similar to the scenario that volkan
describes and hi is absotut right.

Think of an htpc with multiple tuners: the user schedules recordings and
used the system for watching live tv. If the user finished watching live tv
he/she uses the remote to power of the system, regardless of backround
recordings in process . Now its up to the software to keep the system alive
until the recording is finished.
 
V

Volkan Senguel

I came across searching for a solution similar to the scenario that volkan
describes and hi is absotut right.

Think of an htpc with multiple tuners: the user schedules recordings and
used the system for watching live tv. If the user finished watching live
tv
he/she uses the remote to power of the system, regardless of backround
recordings in process . Now its up to the software to keep the system
alive
until the recording is finished.

Thank you joerg, thats exactly what i mean.

the user doesnt handle this with his remote control or simulating any
keystrokes etc....

the system must stay online.

in windows xp was a feature that the system cant suspend, in vista,
microsoft changed this behaviour because a lot of developers had not used
corectly this feature.

any way

has any one a solution for that?

thank you for the help
Volkan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top