[2005] ?? Label Counting with Loops ??
Here is my code. the lblProxyListCount.Text = cboProxies.SelectedIndex + 1 & " / " & cboProxies.Items.Count is not working until the loop is over, i want it to step through the count while the program is working. also the lblStatusBar.Text = "( Testing for working Proxies.... )" is not even showing either. Do labels not have precedence during a loop?
Code:
Private Sub btnTestProxies_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTestProxies.Click
'connect to proxies in list, if connected successfully
'add proxy to cboActiveProxies
lblStatusBar.Text = "( Testing for working Proxies.... )"
Dim sck As Socket = Nothing
Dim i As Integer
Dim IP As String = Split(cboProxies.Text, ":")(0)
Dim Port As String = Split(cboProxies.Text, ":")(1)
' when proxies do not connect, nothing gets added to cboActiveProxies
' when test button is clicked lblStatusBar does not change text either
' its like labels are not taking any precedence
On Error Resume Next
For i = 0 To cboProxies.Items.Count - 1
sck = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
sck.Connect(IP, Port)
If sck.Connected Then
cboActiveProxies.Items.Add(cboProxies.Text)
End If
cboProxies.SelectedIndex = cboProxies.SelectedIndex + 1
lblProxyListCount.Text = cboProxies.SelectedIndex + 1 & " / " & cboProxies.Items.Count
Next i
' lblActiveProxiesCount.Text = cboActiveProxies.SelectedIndex + 1 & " / " & cboActiveProxies.Items.Count
cboActiveProxies.SelectedIndex = 0
sck.Close()
tmrStatusBar.Enabled = True
Re: [2005] ?? Label Counting with Loops ??
If you are using a single thread then it's too busy running your loop to repaint the controls. Either use a worker thread to run the loop so the UI thread is free to repaint the controls or else call the Refresh method of a control after you change its content.