I'm trying to get the current element that For Each
is executing but I'm getting
InvalidOperationException: The list with which the enumerator is associated has been modified. The enumerator can only be used if the list remains constant.
That's the code:
For Each i As String In ListBox1.Items
Try
[..code]
Catch ex As WebException
If ex.Status = WebExceptionStatus.ProtocolError Then
Dim Risposta As DialogResult
Risposta = MessageBox.Show(String.Format("Errore: Impossibile trovare l'SWF {0}. Continuare?", i), "Errore durante il check degli SWF!", MessageBoxButtons.YesNo)
If Risposta = System.Windows.Forms.DialogResult.Yes Then
ListBox1.Items.Remove(i) <- Thats where the error pops up
End If
If Risposta = System.Windows.Forms.DialogResult.No Then
Application.Exit()
End If
Else
MessageBox.Show(String.Format("Errore: {0}", ex.Message), "Errore sconosciuto durante il check degli SWF!")
Application.Exit()
End If
End Try
How can I fix this?