private void refreshProjects() { try { //Turn on the trailing working bar. this.barLoading.Visibility = Visibility.Visible; //Erase what's in the treeview already. this.trvProject.Items.Clear(); //Cancel and kill any existing clients. foreach (ImportExport client in this._Clients) { try { client.CancelAsync(null); client.Connection_Disconnect(); } catch { }; client.Dispose(); } //Clear the list. this._Clients = new List <ImportExport>(); //Create the clients. foreach (Connect.SpiraProject Project in this._Projects) { //Create the client. ImportExport client = new ImportExport(); client.UnsafeAuthenticatedConnectionSharing = false; client.AllowAutoRedirect = true; client.PreAuthenticate = true; client.Timeout = 10000; client.Url = Project.ServerURL.AbsoluteUri + Connect.SpiraProject.URL_APIADD; client.CookieContainer = new System.Net.CookieContainer(); //Attach events. (Real work done here.) client.Connection_Authenticate2Completed += new Connection_Authenticate2CompletedEventHandler(client_FinishConnecting); client.System_GetProductVersionCompleted += new System_GetProductVersionCompletedEventHandler(client_FinishConnecting); client.Connection_ConnectToProjectCompleted += new Connection_ConnectToProjectCompletedEventHandler(client_FinishConnecting); client.Incident_RetrieveCompleted += new Incident_RetrieveCompletedEventHandler(client_FinishIncident); client.Requirement_RetrieveCompleted += new Requirement_RetrieveCompletedEventHandler(client_FinishRequirement); client.Task_RetrieveCompleted += new Task_RetrieveCompletedEventHandler(client_FinishTask); //Create the userstate. ObjectState evtObj = new ObjectState(); evtObj.curSearchIsMine = true; evtObj.Project = Project; //Add it to the list. this._Clients.Add(client); //Add a new project node to the tree. TreeViewItem projNode = createProjectNode(Project.ToString()); evtObj.NodeNumber = this.trvProject.Items.Add(projNode); //Fire off the connection.. client.Connection_Authenticate2Async(Project.UserName, Project.UserPass, this._resources.GetString("strAddinProgNamePretty"), evtObj); } //If no projects, hide the bar. if (this._Clients.Count == 0) { this.barLoading.Visibility = Visibility.Collapsed; } } catch (Exception ex) { Connect.logEventMessage("wpfProjectTree::refreshProjects", ex, System.Diagnostics.EventLogEntryType.Error); } }