Pausar un bucle for para esperar la interacción del usuario

I'm having a bit of a problem figuring out how to pause a for...next loop to await user interaction. I'm comparing the hashes of different files in a for...next loop and if they are different, I want to pause the loop until the user decided which file to keep.

Here's my code, so i hope you see what I'm trying to do.

 For i = 0 To ListBox1.Items.Count - 1
        If GetCRC32(ListBox1.Items.Item(i)) = GetCRC32(ListBox2.Items.Item(i)) Then
            log("same")
        Else

            Dim v1 As String = ListBox1.Items.Item(i)
            Dim v2 As String = ListBox2.Items.Item(i)
            Dim f1 As New FileInfo(v1)
            Dim f2 As New FileInfo(v2)
            Dim c As String
            If f1.LastWriteTime > f2.LastWriteTime Then
                c = v1
            Else
                c = v2
            End If
            RichTextBox1.Text = v1 & " and " & v2 & " seem to be different." & vbCrLf & _
                "Last changed:" & c
        End If
    Next

The user-interaction is via two buttons, which I have no code for yet...

preguntado el 04 de marzo de 14 a las 11:03

No need to pause the loop explicitly, just put the user interaction in directly. -

sounds like you want to interrupt your loop with a messagebox: msdn.microsoft.com/en-us/library/aa969773(v=vs.110).aspx -

I also thought this through, might be the best solution. Thank you guys! -

use environment.newline.. not vbCrLf. Also, you should consider doing a multithreaded application for this purpose/behavior/condition. -

1 Respuestas

Why dont you use Form.ShowDialog in the loop. Stops execution of the loop and you can ask user whatever question you need.

respondido 04 mar '14, 14:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.