Vb.net 暂停for循环以等待用户交互
我在想如何暂停下一个循环以等待用户交互时遇到了一些问题。我正在比较for…next循环中不同文件的哈希值,如果它们不同,我想暂停循环,直到用户决定保留哪个文件 这是我的代码,所以我希望你看到我在做什么Vb.net 暂停for循环以等待用户交互,vb.net,for-loop,user-interaction,Vb.net,For Loop,User Interaction,我在想如何暂停下一个循环以等待用户交互时遇到了一些问题。我正在比较for…next循环中不同文件的哈希值,如果它们不同,我想暂停循环,直到用户决定保留哪个文件 这是我的代码,所以我希望你看到我在做什么 For i = 0 To ListBox1.Items.Count - 1 If GetCRC32(ListBox1.Items.Item(i)) = GetCRC32(ListBox2.Items.Item(i)) Then log("same")
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
用户交互是通过两个按钮进行的,我还没有相应的代码…为什么不在循环中使用Form.ShowDialog呢。
停止循环的执行,您可以向用户询问您需要的任何问题。无需明确暂停循环,只需直接输入用户交互。听起来您想用messagebox中断循环:我也认为这可能是最好的解决方案。谢谢你们!使用environment.newline。。不是vbCrLf。此外,您应该考虑为此目的/行为/条件做一个多线程应用程序。