blange

I am currently using the Compact Framework 2.0 on a Pocket PC 2003 device and there is a setting in start>settings>system>power>advanced called "Turn off device of not used for x minutes." I am curious if there is a way to catch this event so that I might be able to shut down my threads that are dependant on my 802.11x and then Turn Off. Currently what is happening is that I might have a thread in the middle of an HTTP Post when the device powers off and this is not good. Any ideas would be helpfull.

Re: .NET Compact Framework Device Power Off Event

Mahesh kumara

The Poweroff (MessageID - 537) message is sent to all the top level windows by OS.
WParam - 32772

So using MessageWindow Class u can catch this event.

protected override void WndProc(
ref Microsoft.WindowsCE.Forms.Message msg)
{
switch (msg.Msg)
{
case POWER_OFF: 
//modify or handle event;
break;
}
}

I think this will help u..
Mahesh




Re: .NET Compact Framework Device Power Off Event

blange

When I add this void to my code I get "no suitable method found to override".



Re: .NET Compact Framework Device Power Off Event

blange

Well this kinda worked except if I tried to handle the event such as shut down some threads before the device powered off well what would end up happening is that the device would shut off and then if you turned the device back on then the handler would execute.



Re: .NET Compact Framework Device Power Off Event

Anthony Wong - MSFT

I have an article on device power off notifications that you can probably modify to shut down the connections before the device goes into sleep.

http://blogs.msdn.com/anthonywong/archive/2005/06/07/426392.aspx

Cheers,

Anthony Wong [MSFT]





Re: .NET Compact Framework Device Power Off Event

blange

I will go ahead and try this out but by just looking at your code im not quite sure how it is going to stall the power transition so that I will have time to shut down the threads before the device actually powers off.



Re: .NET Compact Framework Device Power Off Event

blange

Well I guess instead of trying to catch the Suspend event I will just disable the "Power Off" feature and then implement my own timer into my program and have it shutdown the threads and then Suspend the device. Since it isn't too hard to catch the Power On event I will just have it fire the threads back up.



Re: .NET Compact Framework Device Power Off Event

Nickeay

Anyone tried this It does not work for me. , it does not get anything when it turns off the screen light or I turn off the power.





Re: .NET Compact Framework Device Power Off Event

MarkIsMobile

Please forgive me ... not sure if this would work, or not (haven't tested it):

Microsoft.WindowsCE.Forms.MobileDevice.Hibernate += new EventHandler(MobileDevice_Hibernate);