我是多线程的新手。我在下面搜索了一些基本示例是代码
Imports System.Threading
Public Class Form1
Dim t As New Thread(AddressOf Me.BackgroundProcess)
Private Sub btnStartThread_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStartThread.Click
t.Start()
End Sub
Private Sub StopButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StopButton.Click
t.Abort()
End Sub
Public Sub BackgroundProcess()
Dim i As Integer = 1
If Me.InvokeRequired Then
Me.Invoke(New MethodInvoker(AddressOf BackgroundProcess))
Else
Do While True
Me.ListBox1.Items.Add("Iteration:" & i)
i += 1
Loop
End If
End Sub
End Class
当我点击开始线程时,我的 UI 变得无响应。这背后的原因是什么。下面是 UI 的屏幕截图