public void UpdateClientList(string str, string type) { if (this.tvClientList.InvokeRequired) { SetListBoxItem d = new SetListBoxItem(UpdateClientList); this.Invoke(d, new object[] { str, type }); } else { // If type is Add, the add Client info in Tree View if (type.Equals("Add")) { this.tvClientList.Nodes[0].Nodes.Add(str); if ((tvClientList.Nodes[0].GetNodeCount(false) > 0) && !tvClientList.Nodes[0].IsExpanded) { tvClientList.Nodes[0].Expand(); } } // Else delete Client information from Tree View else { foreach (TreeNode n in tvClientList.Nodes[0].Nodes) { if (n.Text.Contains(str)) { tvClientList.Nodes.Remove(n); } } } } }
private void UpdateClientList(string str, string type) { if (this.tvClientList.InvokeRequired) { SetListBoxItem d = new SetListBoxItem(UpdateClientList); this.Invoke(d, new object[] { str, type }); } else { if (type.Equals("Add")) { this.tvClientList.Nodes[0].Nodes.Add(str); } else { foreach (TreeNode n in this.tvClientList.Nodes[0].Nodes) { if (n.Text.Equals(str)) { this.tvClientList.Nodes.Remove(n); } } } } }
/// <summary> /// Calls delegate function to update list box. /// IF parameter is "Add", then client information is added in Tree View, /// ELSE entry is deleted from Tree View. /// </summary> /// <param name="str"></param> /// <param name="type"></param> private void UpdateTreeView(string str, string type) { //InvokeRequired compares the thread ID of the //calling thread to that of the current thread. //If these threads are different, it returns true. if (this.TreeViewClientList.InvokeRequired) { //System spawned thread SetListBoxItem d = new SetListBoxItem(UpdateTreeView); this.Invoke(d, new object[] { str, type }); } else { //If type is "Add", then add client info in Tree View if (type.Equals("Add")) { this.TreeViewClientList.Nodes[0].Nodes.Add(str); } else //Delete client information from tree view { foreach (TreeNode n in this.TreeViewClientList.Nodes[0].Nodes) { if (n == null) { return; } if (n.Text.Equals(str)) { this.TreeViewClientList.Nodes.Remove(n); } } } } }
/// <summary> /// Delegate Function to update List box. /// If type parameter is "Add", then client information is added in Tree View /// else the entry is delete from Tree View. /// </summary> /// <param name="str"></param> private void UpdateClientList(string str, string type) { // InvokeRequired required compares the thread ID of the // calling thread to the thread ID of the creating thread. // If these threads are different, it returns true. if (this.tvClientList.InvokeRequired) { SetListBoxItem d = new SetListBoxItem(UpdateClientList); this.Invoke(d, new object[] { str, type }); } else { // If type is Add, the add Client info in Tree View if (type.Equals("Add")) { this.tvClientList.Nodes[0].Nodes.Add(str); } // Else delete Client information from Tree View else { foreach (TreeNode n in this.tvClientList.Nodes[0].Nodes) { if (n.Text.Equals(str)) { this.tvClientList.Nodes.Remove(n); } } } } }
private async void UpdateConnectedClients(string str, string type) { if (!lvConnectedClients.Dispatcher.HasThreadAccess) { SetListBoxItem d = UpdateConnectedClients; await ThreadPool.RunAsync(operation => UIDispatcher.Execute(() => AddItem(str, type))); } else { AddItem(str, type); } }
private void UpdateConnectedClients(string str, string type) { // InvokeRequired required compares the thread ID of the // calling thread to the thread ID of the creating thread. // If these threads are different, it returns true. if (!connectedClients.Dispatcher.CheckAccess()) { SetListBoxItem d = UpdateConnectedClients; connectedClients.Dispatcher.Invoke(d, str, type); } else { // If type is Add, the add Client info in Tree View if (type.Equals("Add")) { connectedClients.Items.Add(str); } // Else delete Client information from Tree View else { connectedClients.Items.Remove(str); } } }