So I don't know how to ask this question and might be one reason I am having issues finding the answers anywhere.
So my setup is that I have a class
public class Connection
{
public static event EventHandler LogggedIn;
public static TDConnection TDC {get;set;}
public string Authenticate(){...}
public static void Login()
{
if (Connection.TDC.Connected)
{
_bw = new BackgroundWorker
{
WorkerReportsProgress = true,
WorkerSupportsCancellation = true
};
_bw.DoWork += ConnectToProject_DoWork;
_bw.RunWorkerCompleted += ConnectToProject_RunWorkerCompleted;
_bw.RunWorkerAsync(Connection.TDC);
}
}
private static void ConnectToProject_DoWork(object o, DoWorkEventArgs e)
{
Connection.TDC.ConnectProjectEx(Connection.Domain, Connection.Project, Connection.UserName, Utilities.Encryption.AESEncryption.Decrypt(Connection.Password, "fsd*#(dfs(((>>>???fdjs"));
}
private static void ConnectToProject_RunWorkerCompleted(object o, RunWorkerCompletedEventArgs e)
{
LogggedIn(null, new EventArgs());
}
}
In my main class I instantiate a new Connection and call Login which opens a new connection to ALM in TDConnection. In my thread I want to use this already open connection inside of my thread. From what I have read, if I do this my UI will block because I am using the methods for the member on the UI thread even though I am inside of the background worker.
One solution I have found to do this:
private static void ConnectToProject_DoWork(object o, DoWorkEventArgs e)
{
TDConnection conn = new TDConnection();
conn.InitConnectionEx(QCURL);
conn.Login();
conn.ConnectProject();
e.Result = conn;
}
I would prefer not to do this because I have already logged in and it takes extra time to do this.
I have tried passing Connection.TDC in with _bw.RunorkerAsync(Connection.TDC) but this does not work either obviously.
Is there any way I can use the already established connection and not block the UI while it is connecting?