How do I tell if my application is running in an RDP session

后端 未结 4 780
旧时难觅i
旧时难觅i 2020-12-30 02:09

I have a .net winforms app which has a few animation effects, fade ins and scroll animations etc. These work fine however if I\'m in a Remote Desktop Protocol session the a

4条回答
  •  自闭症患者
    2020-12-30 02:55

    See a similar question i asked: How to check if we’re running on battery?

    Because if you're running on battery you also want to disable animations.

    /// 
    /// 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;    
        }
    }
    

    And then to check if you're running on battery:

    /// 
    /// 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;
          }
       }
    }
    

    Which you can just combine into one:

    public Boolean UseAnimations()
    {
       return 
          (!System.Windows.Forms.SystemInformation.TerminalServerSession) &&
          (System.Windows.Forms.SystemInformation.PowerStatus.PowerLineStatus != PowerLineStatus.Offline);
    }
    

    Note: This question was already asked (Determine if a program is running on a Remote Desktop)

提交回复
热议问题