我有一个.net winforms应用程序,它有一些动画效果,淡入和滚动动画等.这些工作正常但是如果我在远程桌面协议会话中动画开始grate.
有人可以建议一种方法来确定应用程序是否在RDP会话中运行,这样我可以在这种情况下关闭效果吗?
假设您至少使用的是.NET Framework 2.0,则无需使用P/Invoke:只需检查System.Windows.Forms.SystemInformation.TerminalServerSession
(MSDN)的值即可.
看到我问的类似问题:如何检查我们是否使用电池运行?
因为如果您使用电池运行,您还需要禁用动画.
////// 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! /// /// ///public static Boolean IsRemoteSession { //This is just a friendly wrapper around the built-in way get { return System.Windows.Forms.SystemInformation.TerminalServerSession; } }
然后检查你是否使用电池运行:
////// Indicates if we're running on battery power. /// If we are, then disable CPU wasting things like animations, background operations, network, I/O, etc /// 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; } } }
您可以将其组合成一个:
public Boolean UseAnimations() { return (!System.Windows.Forms.SystemInformation.TerminalServerSession) && (System.Windows.Forms.SystemInformation.PowerStatus.PowerLineStatus != PowerLineStatus.Offline); }
注意:此问题已被提出(确定程序是否在远程桌面上运行)