mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-02-03 21:25:13 +00:00
Page:
PowerMonitor
Pages
ASP.Net
About
Advanced Migration Topics
App
AutoUpdater
Clipboard
Configuration
Console App
Custom_main
Debugging
Dialog
Dock
GlobalShortcut
Home
HostHook
IpcMain
Menu
Migration Checks
Migration Guide
NativeTheme
Notification
Overview
Package Building
Package Description
PowerMonitor
Screen
Shell
Startup Methods
System Requirements
Tray
WebContents
What's New
WindowManager
Clone
1
PowerMonitor
github-actions[bot] edited this page 2025-10-31 16:53:39 +00:00
Monitor system power events like sleep, wake, and battery status.
Overview
The Electron.PowerMonitor API provides access to system power events and state changes. This includes monitoring when the system is going to sleep, waking up, or changing power sources.
Events
⚡ OnAC
Emitted when the system changes to AC power.
⚡ OnBattery
Emitted when system changes to battery power.
⚡ OnLockScreen
Emitted when the system is about to lock the screen.
⚡ OnResume
Emitted when system is resuming.
⚡ OnShutdown
Emitted when the system is about to reboot or shut down.
⚡ OnSuspend
Emitted when the system is suspending.
⚡ OnUnLockScreen
Emitted when the system is about to unlock the screen.
Usage Examples
Basic Power Event Monitoring
// Monitor system sleep/wake
Electron.PowerMonitor.OnSuspend += () =>
{
Console.WriteLine("System going to sleep");
// Save application state
SaveApplicationState();
};
Electron.PowerMonitor.OnResume += () =>
{
Console.WriteLine("System waking up");
// Restore application state
RestoreApplicationState();
};
Screen Lock/Unlock Monitoring
// Handle screen lock events
Electron.PowerMonitor.OnLockScreen += () =>
{
Console.WriteLine("Screen locking");
// Pause real-time operations
PauseRealTimeOperations();
};
Electron.PowerMonitor.OnUnLockScreen += () =>
{
Console.WriteLine("Screen unlocking");
// Resume real-time operations
ResumeRealTimeOperations();
};
Power Source Changes
// Monitor power source changes
Electron.PowerMonitor.OnAC += () =>
{
Console.WriteLine("Switched to AC power");
// Adjust power-intensive operations
EnablePowerIntensiveFeatures();
};
Electron.PowerMonitor.OnBattery += () =>
{
Console.WriteLine("Switched to battery power");
// Reduce power consumption
EnablePowerSavingMode();
};
System Shutdown Handling
// Handle system shutdown
Electron.PowerMonitor.OnShutdown += () =>
{
Console.WriteLine("System shutting down");
// Save critical data and exit gracefully
SaveAndExit();
};
Application State Management
private bool isSuspended = false;
public void InitializePowerMonitoring()
{
// Track suspension state
Electron.PowerMonitor.OnSuspend += () =>
{
isSuspended = true;
OnSystemSleep();
};
Electron.PowerMonitor.OnResume += () =>
{
isSuspended = false;
OnSystemWake();
};
// Handle screen lock for security
Electron.PowerMonitor.OnLockScreen += () =>
{
OnScreenLocked();
};
}
private void OnSystemSleep()
{
// Pause network operations
PauseNetworkOperations();
// Save unsaved work
AutoSaveDocuments();
// Reduce resource usage
MinimizeResourceUsage();
}
private void OnSystemWake()
{
// Resume network operations
ResumeNetworkOperations();
// Check for updates
CheckForUpdates();
// Restore full functionality
RestoreFullFunctionality();
}
private void OnScreenLocked()
{
// Hide sensitive information
HideSensitiveData();
// Pause real-time features
PauseRealTimeFeatures();
}
Battery Status Monitoring
// Monitor battery status changes
Electron.PowerMonitor.OnAC += () =>
{
Console.WriteLine("Plugged in - full performance mode");
EnableFullPerformanceMode();
};
Electron.PowerMonitor.OnBattery += () =>
{
Console.WriteLine("On battery - power saving mode");
EnablePowerSavingMode();
};
Related APIs
- Electron.App - Application lifecycle events
- Electron.Notification - Notify users about power events
Additional Resources
- Electron PowerMonitor Documentation - Official Electron power monitor API
- API Overview

- Electron.App

- Electron.Dialog

- Electron.Menu

- Electron.WindowManager

- Electron.Shell

- Electron.Screen

- Electron.Notification

- Electron.Tray

- Electron.Clipboard

- Electron.Dock

- Electron.HostHook

- Electron.IpcMain

- Electron.GlobalShortcut

- Electron.AutoUpdater

- Electron.NativeTheme

- Electron.PowerMonitor

Want to contribute to this documentation? Please fork and create a PR! The Wiki is autogenerated from the /docs content in the repository.