title: RDP Client - AxHost.InvalidActiveXStateException
body: <p>I working on application that will optimize my job, with multiple connection by means RDP to my  servers. At that point I will like to do a single windows form that show me all my servers. With my appropriate knowledge - I will like to add programmatically <code>AxMsRdpClient2</code> or <code>AxMsTscAxNotSafeForScripting</code> control in my windows form. At start I have a Form1 where I save my credential (IP,USER,PASS) and with simple <code>FOR</code>  I trung to add ActiveX Client to my Form2 and connect to the servers.</p>
  
  <p>And here I have the problem. Lets see my code below.</p>
  
  <p>call from Form1() ></p>
  
  <pre><code>var btt = new RunRDP();
      for (int i = 0; i &lt; 15; i++)
      {
          btt.PozitionMaster();
      } 
  </code></pre>
  
  <p>RunRDP Class:</p>
  
  <pre><code>private static int _count;
  private static int _row = 4;
  private static int _colum = 4;
  private static int _objId;
  
  public void PozitionMaster()
      {
          if (_count != 6)
          {
              UInitializer(_objId++, _row, _colum);
              _row += 196;
              _count++;
  
          }
          else
          {
              _colum += 196;
              _row = 4;
              _count = 0;
          }
      }
  </code></pre>
  
  <p>UInitializer function:</p>
  
  <pre><code>public AxMsRdpClient2 rdpClient;
  
          public void UInitializer(int id, int x, int y)
          {
              Form2 ippo = new Form2();
              rdpClient = new AxMsRdpClient2();
  
              rdpClient.UserName = "username";
              rdpClient.Server = "192.168.0.100";
              rdpClient.Height = y;
              rdpClient.Width = x;
  
              rdpClient.BeginInit();
              rdpClient.CreateControl();
  
  
              if (ippo.InvokeRequired)
              {
                  ippo.Invoke(new Action(() =&gt; ippo.Controls.Add(rdpClient)));
                  ippo.Invoke(new Action(() =&gt; ippo.Update()));
              }
              else
              {
                  ippo.Controls.Add(rdpClient);
              }
  
              //this.Controls.Add(rdpClient);
  
              rdpClient.AdvancedSettings2.RDPPort = 3389;
              rdpClient.AdvancedSettings2.ClearTextPassword = "hello_rdp";//     
              rdpClient.ColorDepth = 16;//     
              rdpClient.FullScreen = false;//     
  
              rdpClient.Connect();    
          }
  </code></pre>
  
  <p>get that error:</p>
  
  <pre><code>    An unhandled exception of type 'System.Windows.Forms.AxHost.
  InvalidActiveXStateException' occurred in AxInterop.MSTSCLib.dll
  
  {"Exception of type 'System.Windows.Forms.AxHost+InvalidActiveXStateException' was thrown."}
  </code></pre>