Exemplo n.º 1
0
        private void RefreshNetworkInterfaces()
        {
            if (InvokeRequired)
            {
                BeginInvoke((MethodInvoker)RefreshNetworkInterfaces);
                return;
            }

            // Get all IP v4 addresses
            List <string> newList = GetIPv4Addresses();

            // Add
            foreach (string address in newList)
            {
                if (!Items.Contains(address))
                {
                    // Added
                    Items.Add(address);
                }
            }

            // Delete
            for (int i = 0; i < Items.Count; i++)
            {
                if (!any.Equals(Items[i]) && !newList.Contains((String)Items[i]))
                {
                    // Removed
                    if (SelectedIndex == i)
                    {
                        InterfaceDeleted?.Invoke((String)Items[i]);
                    }
                    Items.RemoveAt(i);
                }
            }
        }
        private void RefreshNetworkInterfaces()
        {
            if (InvokeRequired)
            {
                BeginInvoke((MethodInvoker)RefreshNetworkInterfaces);
                return;
            }

            // Get all IP v4 addresses
            List <string> newList = GetIPAddresses();

            if (IncludeIPAddressAny)
            {
                newList.Add(IPAddress.Any.ToString());
                newList.Add(IPAddress.IPv6Any.ToString());
            }

            // Add
            foreach (string address in newList)
            {
                if (!comboBox.Items.Contains(address))
                {
                    // Added
                    comboBox.Items.Add(address);
                }
            }

            // Delete
            for (int i = 0; i < comboBox.Items.Count; i++)
            {
                if (!newList.Contains((String)comboBox.Items[i]))
                {
                    // Removed
                    if (comboBox.SelectedIndex == i)
                    {
                        InterfaceDeleted?.Invoke();
                    }
                    comboBox.Items.RemoveAt(i);
                }
            }
        }