コード例 #1
0
        private void loadPort(string portNumberSelected)
        {
            lv_port.Items.Clear();
            lv_link.Items.Clear();

            if (ip == null)
            {
                return;
            }

            PortConnection            portConn = new PortConnection(ip.ipAddress);
            Dictionary <string, Port> lst      = new Dictionary <string, Port>();

            lst = Task.Run(() => portConn.GetAll()).Result;

            foreach (Port port in lst.Values)
            {
                ListViewItem item = new ListViewItem(ip.ipAddress.Replace("_", "."));
                item.SubItems.Add(port.portNumber);
                item.SubItems.Add(port.active.ToString());
                item.SubItems.Add(port.data.ToString());
                item.SubItems.Add(port.die.ToString());
                item.SubItems.Add(port.port.ToString());

                if (portNumberSelected != null && port.portNumber == portNumberSelected)
                {
                    item.BackColor = Color.Blue;
                }
                lv_port.Items.Add(item);
            }
        }
コード例 #2
0
        private void loadPort()
        {
            bool success = false;
            int  loop    = 0;

            do
            {
                if (loop == 10)
                {
                    break;
                }
                try
                {
                    lv_port.Items.Clear();
                    lv_link.Items.Clear();
                    lbl_portSelected.Text = "Port Selected: ";

                    if (IPSelected == null)
                    {
                        return;
                    }

                    PortConnection            portConn = new PortConnection(IPSelected.ipAddress);
                    Dictionary <string, Port> lst      = new Dictionary <string, Port>();
                    lst = Task.Run(() => portConn.GetAll()).Result;

                    foreach (Port port in lst.Values)
                    {
                        ListViewItem item = new ListViewItem(IPSelected.ipAddress.Replace("_", "."));
                        item.SubItems.Add(port.portNumber);
                        item.SubItems.Add(port.active.ToString());
                        item.SubItems.Add(port.data.ToString());
                        item.SubItems.Add(port.die.ToString());
                        item.SubItems.Add(port.port.ToString());
                        item.SubItems.Add(port.language.ToString());

                        lv_port.Items.Add(item);
                    }
                    success = true;
                }
                catch
                {
                    loop++;
                    Thread.Sleep(1000);
                }
            } while (!success);

            if (!success)
            {
                MessageBox.Show("Đã thử load " + loop + " lần mà *** đc :))");
            }
        }