From: Brett on
I have an application that needs to detect if there are any pending
suspend/hibernate requests.

The application needs to set up a wake timer so that the system wakes from
suspend/hibernate after some length of time.

I'm using .NET Framework 2.0 with C#, but I can use Interop when necessary.
I was just using the Microsoft.Win32.SystemEvents.PowerModeChanged handler,
but I'm concerned that in some cases by the time I get the "Suspend"
PowerMode event, there may not be enough time to fully set my wake timer. In
one case I have seen, the system seems to have some other services that keep
the system from suspending for some time and it doesn't suspend until after
my timer has expired.

My plan is to have a thread spin on querying if there are any
Suspend/Hibernate requests and continually reset the wake timer if there is.
Then, when it resumes from suspend, the query will return false and I can
continue life as normal.

Thanks for any help in advance!
From: Pavel A. on
This is hard to do without a helper driver in the kernel.
If you disclose what is the bigger problem , you can get better answers.

Regards,
--pa


"Brett" <elderdodds(a)yahoo.notnet> wrote in message
news:CE08AD5F-9908-4022-8B28-C88B6323D90F(a)microsoft.com...
> I have an application that needs to detect if there are any pending
> suspend/hibernate requests.
>
> The application needs to set up a wake timer so that the system wakes from
> suspend/hibernate after some length of time.
>
> I'm using .NET Framework 2.0 with C#, but I can use Interop when
> necessary.
> I was just using the Microsoft.Win32.SystemEvents.PowerModeChanged
> handler,
> but I'm concerned that in some cases by the time I get the "Suspend"
> PowerMode event, there may not be enough time to fully set my wake timer.
> In
> one case I have seen, the system seems to have some other services that
> keep
> the system from suspending for some time and it doesn't suspend until
> after
> my timer has expired.
>
> My plan is to have a thread spin on querying if there are any
> Suspend/Hibernate requests and continually reset the wake timer if there
> is.
> Then, when it resumes from suspend, the query will return false and I can
> continue life as normal.
>
> Thanks for any help in advance!

From: Brett on
Thanks for the response

I'm not opposed to a helper driver option (if necessary), I've had to do
this on other projects.

This particular project is a System Suspend Test which will force the system
in/out of suspend over and over.

The problem I'm seeing is that in one instance, the SetSuspendState function
returns true, but doesn't halt thread execution. It then enters suspend some
time afterward (presumably because the original SetSuspendState function
queued a suspend). At that point, the timer has been cancelled and the system
remains suspended until the user brings it back out.

I felt that checking a Suspend queue would be the best way to do this, but
if there's no API easily available, I'll use a little more creativity to come
up with a solution. I had implemented a solution which I felt was rather
clunky, so I was hoping for something a little cleaner.

"Pavel A." wrote:

> This is hard to do without a helper driver in the kernel.
> If you disclose what is the bigger problem , you can get better answers.
>
> Regards,
> --pa
>
>
> "Brett" <elderdodds(a)yahoo.notnet> wrote in message
> news:CE08AD5F-9908-4022-8B28-C88B6323D90F(a)microsoft.com...
> > I have an application that needs to detect if there are any pending
> > suspend/hibernate requests.
> >
> > The application needs to set up a wake timer so that the system wakes from
> > suspend/hibernate after some length of time.
> >
> > I'm using .NET Framework 2.0 with C#, but I can use Interop when
> > necessary.
> > I was just using the Microsoft.Win32.SystemEvents.PowerModeChanged
> > handler,
> > but I'm concerned that in some cases by the time I get the "Suspend"
> > PowerMode event, there may not be enough time to fully set my wake timer.
> > In
> > one case I have seen, the system seems to have some other services that
> > keep
> > the system from suspending for some time and it doesn't suspend until
> > after
> > my timer has expired.
> >
> > My plan is to have a thread spin on querying if there are any
> > Suspend/Hibernate requests and continually reset the wake timer if there
> > is.
> > Then, when it resumes from suspend, the query will return false and I can
> > continue life as normal.
> >
> > Thanks for any help in advance!
>
From: Don Burn on
Would the PwrTest from the WDK in a script do what you need?


Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr




> -----Original Message-----
> From: Brett [mailto:elderdodds(a)yahoo.notnet]
> Posted At: Wednesday, March 31, 2010 2:35 PM
> Posted To: microsoft.public.win32.programmer.kernel
> Conversation: Quering Power Requests
> Subject: Re: Quering Power Requests
>
> Thanks for the response
>
> I'm not opposed to a helper driver option (if necessary), I've had to do
> this
> on other projects.
>
> This particular project is a System Suspend Test which will force the
> system
> in/out of suspend over and over.
>
> The problem I'm seeing is that in one instance, the SetSuspendState
> function
> returns true, but doesn't halt thread execution. It then enters suspend
> some
> time afterward (presumably because the original SetSuspendState function
> queued a suspend). At that point, the timer has been cancelled and the
> system
> remains suspended until the user brings it back out.
>
> I felt that checking a Suspend queue would be the best way to do this,
> but if
> there's no API easily available, I'll use a little more creativity to
> come up
> with a solution. I had implemented a solution which I felt was rather
> clunky,
> so I was hoping for something a little cleaner.
>
> "Pavel A." wrote:
>
> > This is hard to do without a helper driver in the kernel.
> > If you disclose what is the bigger problem , you can get better
> > answers.
> >
> > Regards,
> > --pa
> >
> >
> > "Brett" <elderdodds(a)yahoo.notnet> wrote in message
> > news:CE08AD5F-9908-4022-8B28-C88B6323D90F(a)microsoft.com...
> > > I have an application that needs to detect if there are any pending
> > > suspend/hibernate requests.
> > >
> > > The application needs to set up a wake timer so that the system
> > > wakes from suspend/hibernate after some length of time.
> > >
> > > I'm using .NET Framework 2.0 with C#, but I can use Interop when
> > > necessary.
> > > I was just using the Microsoft.Win32.SystemEvents.PowerModeChanged
> > > handler,
> > > but I'm concerned that in some cases by the time I get the "Suspend"
> > > PowerMode event, there may not be enough time to fully set my wake
> > > timer.
> > > In
> > > one case I have seen, the system seems to have some other services
> > > that keep the system from suspending for some time and it doesn't
> > > suspend until after my timer has expired.
> > >
> > > My plan is to have a thread spin on querying if there are any
> > > Suspend/Hibernate requests and continually reset the wake timer if
> > > there is.
> > > Then, when it resumes from suspend, the query will return false and
> > > I can continue life as normal.
> > >
> > > Thanks for any help in advance!
> >
>
>
> __________ Information from ESET Smart Security, version of virus
> signature
> database 4989 (20100331) __________
>
> The message was checked by ESET Smart Security.
>
> http://www.eset.com
>

From: Brett on
That's a good thought, I may give that a try, though I was hoping for a more
contained solution.
I'm getting that there's nothing I can do to query if a suspend has occured
or not after I request it.

I think I've drilled down the root of my problem to a single system with
Win7 that for some reason will periodically return SetSuspendState true
without actually having gone into and out of suspend.
It does go into suspend, but from what I understand, the thread is supposed
to halt execution until the system resumes from suspend and which point it
will return true. So, perhaps a system-specific bug in powrprof.dll? It works
properly 99% of the time.

Let me know if there are any other suggestions.

Thanks!

"Don Burn" wrote:

> Would the PwrTest from the WDK in a script do what you need?
>
>
> Don Burn (MVP, Windows DKD)
> Windows Filesystem and Driver Consulting
> Website: http://www.windrvr.com
> Blog: http://msmvps.com/blogs/WinDrvr
>
>
>
>
> > -----Original Message-----
> > From: Brett [mailto:elderdodds(a)yahoo.notnet]
> > Posted At: Wednesday, March 31, 2010 2:35 PM
> > Posted To: microsoft.public.win32.programmer.kernel
> > Conversation: Quering Power Requests
> > Subject: Re: Quering Power Requests
> >
> > Thanks for the response
> >
> > I'm not opposed to a helper driver option (if necessary), I've had to do
> > this
> > on other projects.
> >
> > This particular project is a System Suspend Test which will force the
> > system
> > in/out of suspend over and over.
> >
> > The problem I'm seeing is that in one instance, the SetSuspendState
> > function
> > returns true, but doesn't halt thread execution. It then enters suspend
> > some
> > time afterward (presumably because the original SetSuspendState function
> > queued a suspend). At that point, the timer has been cancelled and the
> > system
> > remains suspended until the user brings it back out.
> >
> > I felt that checking a Suspend queue would be the best way to do this,
> > but if
> > there's no API easily available, I'll use a little more creativity to
> > come up
> > with a solution. I had implemented a solution which I felt was rather
> > clunky,
> > so I was hoping for something a little cleaner.
> >
> > "Pavel A." wrote:
> >
> > > This is hard to do without a helper driver in the kernel.
> > > If you disclose what is the bigger problem , you can get better
> > > answers.
> > >
> > > Regards,
> > > --pa
> > >
> > >
> > > "Brett" <elderdodds(a)yahoo.notnet> wrote in message
> > > news:CE08AD5F-9908-4022-8B28-C88B6323D90F(a)microsoft.com...
> > > > I have an application that needs to detect if there are any pending
> > > > suspend/hibernate requests.
> > > >
> > > > The application needs to set up a wake timer so that the system
> > > > wakes from suspend/hibernate after some length of time.
> > > >
> > > > I'm using .NET Framework 2.0 with C#, but I can use Interop when
> > > > necessary.
> > > > I was just using the Microsoft.Win32.SystemEvents.PowerModeChanged
> > > > handler,
> > > > but I'm concerned that in some cases by the time I get the "Suspend"
> > > > PowerMode event, there may not be enough time to fully set my wake
> > > > timer.
> > > > In
> > > > one case I have seen, the system seems to have some other services
> > > > that keep the system from suspending for some time and it doesn't
> > > > suspend until after my timer has expired.
> > > >
> > > > My plan is to have a thread spin on querying if there are any
> > > > Suspend/Hibernate requests and continually reset the wake timer if
> > > > there is.
> > > > Then, when it resumes from suspend, the query will return false and
> > > > I can continue life as normal.
> > > >
> > > > Thanks for any help in advance!
> > >
> >
> >
> > __________ Information from ESET Smart Security, version of virus
> > signature
> > database 4989 (20100331) __________
> >
> > The message was checked by ESET Smart Security.
> >
> > http://www.eset.com
> >
>
> .
>