Version: 3.1.5
wxPowerResourceBlocker Class Reference

#include <wx/power.h>

Detailed Description

Helper RAII class ensuring that power resources are released.

A wxPowerResourceBlocker object acquires a power resource in the constructor and releases it in the destructor making it impossible to forget to release the power resource (which would prevent suspending or screen power off until the application ends).


void MyWindow::DoSomething()
blocker(wxPOWER_RESOURCE_SYSTEM, "Downloading something important");
if ( !blocker.IsInEffect() )
// If the resource could not be acquired, tell the user that he has
// to keep the system alive
wxLogMessage("Warning: system may suspend while downloading.");
// Run an important download and the system will not suspend while downloading
for ( int i = 0; i < download.size(); ++i )
// wxPOWER_RESOURCE_SYSTEM automatically released here.

Library:  wxBase
Category:  Miscellaneous
See also

Public Member Functions

 wxPowerResourceBlocker (wxPowerResourceKind kind, const wxString &reason=wxString())
 Acquires the power resource. More...
bool IsInEffect () const
 Returns whether the power resource could be acquired. More...
 ~wxPowerResourceBlocker ()
 Releases the power resource. More...

Constructor & Destructor Documentation

wxPowerResourceBlocker::wxPowerResourceBlocker ( wxPowerResourceKind  kind,
const wxString reason = wxString() 

Acquires the power resource.

Uses the same parameters as wxPowerResource::Acquire().

wxPowerResourceBlocker::~wxPowerResourceBlocker ( )

Releases the power resource.

See also

Member Function Documentation

bool wxPowerResourceBlocker::IsInEffect ( ) const

Returns whether the power resource could be acquired.

This can be used to inform the user that the application will not prevent automatic suspending.

See also