I am trying to dynamically add serial ports to a combobox as the user inserts a usb. I have the code below so far. What I am having trouble in is that i cannot delete the serial port when the user pulls out the usb.
Public Sub adding_items()
Do While x > 0
Dim Ports As String() = IO.Ports.SerialPort.GetPortNames()
For Each Port In Ports
If ComboBox1.Items.Contains(Port) Then
Else
ComboBox1.Items.Add(Port)
End If
If ComboBox2.Items.Contains(Port) Then
Else
ComboBox2.Items.Add(Port)
End If
If ComboBox3.Items.Contains(Port) Then
Else
ComboBox3.Items.Add(Port)
End If
Next Port
'deleting = New Threading.Thread(AddressOf deleting_items)
'deleting.Start()
'Thread.Sleep(5000)
Loop
End Sub
Please note I am not opening or closing any serial ports, just assigning them to the comboboxes.