Ver una pregunta similar le pregunté: How to check if we’re running on battery?
Porque si se está ejecutando en la batería también desea desactivar animaciones.
/// <summary>
/// Indicates if we're running in a remote desktop session.
/// If we are, then you MUST disable animations and double buffering i.e. Pay your taxes!
///
/// </summary>
/// <returns></returns>
public static Boolean IsRemoteSession
{
//This is just a friendly wrapper around the built-in way
get
{
return System.Windows.Forms.SystemInformation.TerminalServerSession;
}
}
Y a continuación, para comprobar si se está ejecutando en la batería:
/// <summary>
/// Indicates if we're running on battery power.
/// If we are, then disable CPU wasting things like animations, background operations, network, I/O, etc
/// </summary>
public static Boolean IsRunningOnBattery
{
get
{
PowerLineStatus pls = System.Windows.Forms.SystemInformation.PowerStatus.PowerLineStatus;
if (pls == PowerLineStatus.Offline)
{
//Offline means running on battery
return true;
}
else
{
return false;
}
}
}
cual sólo se puede combinar en una sola:
public Boolean UseAnimations()
{
return
(!System.Windows.Forms.SystemInformation.TerminalServerSession) &&
(System.Windows.Forms.SystemInformation.PowerStatus.PowerLineStatus != PowerLineStatus.Offline);
}
Nota: Esta pregunta ya se le preguntó (Determine if a program is running on a Remote Desktop)
Tenga en cuenta que 'TerminalServerSession' es simplemente un contenedor de una llamada a' GetSystemMetrics (SM_REMOTESESSION) '. – Cameron