title: VB.net Terminal Server application
body: <p>im working on an terminal service application for personal use that allows me to list and manage all my RDP sessions via tabs (I know these exists, but using it as a small learning project also). I was wondering if anyone could help with a few items. I am trying to dynamically create and add tabs and the RDP control onto each tab. This seems to be working OK for creating the first tab page and control but fails on the subsequent ones with the error below Code below: </p>
  
  <pre><code>    Dim theNewTabPage As New DevExpress.XtraTab.XtraTabPage()
      theNewTabPage.Text = txtserver.Text
      theNewTabPage.Name = Minute(DateTime.Now) &amp; Second(DateTime.Now)
  
      Dim RDPCONTROL As New AxMSTSCLib.AxMsRdpClient9NotSafeForScripting
      RDPCONTROL.Dock = DockStyle.Fill
      'Just a test to ensure unique name
      RDPCONTROL.Name = Minute(DateTime.Now) &amp; Second(DateTime.Now) 
      XtraTabControl1.TabPages.Add(theNewTabPage)
      theNewTabPage.Controls.Add(RDPCONTROL)
      Try
          RDPCONTROL.Server = txtserver.Text
          RDPCONTROL.Domain = txtdomain.text
          RDPCONTROL.UserName = txtusername.Text
          Dim secured As MSTSCLib.IMsTscNonScriptable = DirectCast(RDPCONTROL.GetOcx(), MSTSCLib.IMsTscNonScriptable)
          secured.ClearTextPassword = txtpassword.Text
          RDPCONTROL.Connect()
      Catch ex As Exception
          MessageBox.Show(ex.Message)
      End Try`
  </code></pre>
  
  <p>Error when creating the second connection:</p>
  
  <pre><code>Using ex.message: exception of type 'system.windows.forms.axhost+invalidactivexstateexception  was thrown
  Using ex.tostring: property set of 'Server' cannot be invoked at this time
  </code></pre>
  
  <p>The next item is how can i detect if the RDP session was disconnected on the tab and then pop-up a message and close the required tab</p>