Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Power to the People : Page 3

Software can have a huge effect on the life span of a battery; scaling down functionality is an easy way to drastically increase the lifetime of mobile PC battery. Do your users a favor and find out how to optimize your applications' power requirements.


advertisement
Dealing with Power On Windows Vista
Windows Vista improves how your application can interact with Windows' power management. The WM_POWERBROADCAST message is still sent to notify the application of changes. This does mean that there needs to be a Window handle to receive these messages.

Windows Vista then provides a number of GUIDs that you can use to register to receive information about particular features of the power. For example, if you want your application to be notified of the power source, register for the GUID_ACDC_POWER_SOURCE GUID.

The registration method is called RegisterPowerSettingNotification and takes a GUID parameter that identifies the notification for which you are registering.

hPowerSrc = RegisterPowerSettingNotification( this.Handle, ref GUID_ACDC_POWER_SOURCE, DEVICE_NOTIFY_WINDOW_HANDLE);

The returned handle should then be used to unregister the notification.

Windows Vista improves how you can interact with the power management APIs.

UnregisterPowerSettingNotification(hPowerSrc);

When the notification messages are sent, they are accompanied by a structure that is passed in the lParam of the Windows message. This structure is a POWERBROADCAST_SETTING, defined here in C#.



[StructLayout(LayoutKind.Sequential, Pack = 4)] internal struct POWERBROADCAST_SETTING { public Guid PowerSetting; public Int32 DataLength; }

The PowerSetting field in the structure identifies the setting or event notification you are receiving. Remember, you can register to be notified of changes to multiple power settings.

In Windows Vista, it is easy for the user to change the active Power Plan. A Power Plan specifies the power management settings in effect on the computer. The three power plans that will ship with Windows Vista are Automatic, High Performance, and Power Saver.

As the names suggest, these power plans indicate to the running application how to behave regarding power consumption. In Automatic mode, it is best practice to scale functionality based on criteria, such as application demand, current power source and battery percentage remaining. In High Performance, your application should not scale back functionality to improve battery life; the user has chosen not to worry about battery life and your application should focus on providing the best possible performance. When the user chooses Power Saver, your application should scale back all non-critical functionality to reduce power consumption.

Your application can register for a change in the Power Plan by calling the RegisterPowerSettingNotification method using the GUID_POWERSCHEME_PERSONALITY GUID.

As you can see, it's wise to add power management to your application. Doing this is not hard and can help to improve the user experience by extending the battery life of the device on which your application is run.

To prevent the user experiencing a drained battery, your application should always respond in a timely manner to suspend requests and never block the computer from suspending.

Here is a list of some of the things you should consider when building your application:

  • Determine the power source.
  • Never prevent a request for the system to suspend.
  • When the system resumes, your application should run smoothly, as if it had never been interrupted.
  • When the system resumes, the available devices and power source may have changed. Your application should be reasonably unaffected by these changes or have built-in contingency plans.
  • Reduce the power consumption of your application when the power source is a battery by avoiding polling operations, not running non-critical worker threads, and avoiding unnecessary device (disk, display, Bluetooth, USB) access.


Dr. Neil Roodyn is an independent itinerant consultant, trainer, and author. He travels the world working with software companies. Dr. Neil loves Australia, where he spends the summer enjoying the Sydney lifestyle and helping software development teams get more productive. Dr. Neil spends his other summer each year flying between northern Europe and the USA, working with software teams and writing about his experiences. Neil brings his business and technical skills to the companies he works with to ensure that he has happy customers. You can find out more from his Web site.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap