I have a helpdesk package for our company that I am attempting to integrate with Remote Desktop. Among the functionalities I am looking to implement is the ability to determine (while you are browsing through the list of our clients) if a remote desktop connection is currently available for the selected system. The library I am using is "Microsoft Terminal Services Control" - (AxInterop.MSTSCLib AxMsRdpClient7)
Now my problem is that I want to perform this task (attempt a connection) on a separate thread to prevent blocking the UI (given that I might be attempting a connection on numerous clients at the same time) and thus far have been unsuccessful.
Here is an idea of the code...
public void AttemptLogin(string password)
{
this._thread = new Thread(LoginAttempt);
this._thread.SetApartmentState(ApartmentState.STA);
this._thread.Start(password);
}
protected void LoginAttempt(object password)
{
AxMsRdpClient7 remoteDesktop = new AxMsRdpClient7();
remoteDesktop.CreateControl();
remoteDesktop.UserName = this._username;
remoteDesktop.Server = this._server;
WireEventHandlers(remoteDesktop);
IMsTscNonScriptable passwordContainer = (IMsTscNonScriptable)remoteDesktop.GetOcx();
passwordContainer.ClearTextPassword = password.ToString();
remoteDesktop.Connect();
}
Basically the code above works perfectly if I am executing it in the UI thread and add the control to the forms collection but when I attempt to run this on a separate thread it appears that simply no actions occur. No exceptions are raised on connect(). No events are raised and it seems nothing happens.
I guess what I am hoping for is confirmation that what I am attempting to do (Run a COM component in a thread) IS INFACT POSSIBLE and any further guidance about what steps might be required to get this to work would be highly appreciated.