ServiceBase.OnPowerEvent(PowerBroadcastStatus) Method

Definition

When implemented in a derived class, executes when the computer's power status has changed. This applies to laptop computers when they go into suspended mode, which is not the same as a system shutdown.

C#
protected virtual bool OnPowerEvent(System.ServiceProcess.PowerBroadcastStatus powerStatus);

Parameters

powerStatus
PowerBroadcastStatus

A PowerBroadcastStatus that indicates a notification from the system about its power status.

Returns

When implemented in a derived class, the needs of your application determine what value to return. For example, if a QuerySuspend broadcast status is passed, you could cause your application to reject the query by returning false.

Remarks

Use OnPowerEvent to specify the processing that occurs when the system event indicated in the PowerBroadcastStatus enumeration occurs--for example, when the computer is placed in suspended mode or indicates low battery power.

OnPowerEvent is expected to be overridden when the CanHandlePowerEvent property is true.

Applies to

Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

See also