所以,我是VB.NET的新手,我想创建一个简单的程序来ping和扫描开放端口。但是,ping是可以的,但是扫描端口并没有工作它继续说" ThreadStart不接受参数"我不知道如何解决它。不管怎样,端口扫描部分的代码:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
For i As Integer = Start1.Value To End1.Value
' TT= temp threading
Control.CheckForIllegalCrossThreadCalls = False
Dim TT As New System.Threading.Thread(AddressOf ScanPort)
TT.IsBackground = True
TT.Start(i)
Next
End Sub
答案 0 :(得分:1)
?...所以让它接受参数?
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
For i As Integer = start1.Value To end1.Value
' TT= temp threading
Control.CheckForIllegalCrossThreadCalls = False
Dim TT As New System.Threading.Thread(AddressOf ScanPort)
TT.IsBackground = True
TT.Start(i)
Next
End Sub
Private Sub ScanPort(ByVal portToScan As Integer)
Debug.Print("Scanning Port: " & portToScan)
System.Threading.Thread.Sleep(1000)
End Sub
使用 Option Strict On ,它看起来像这样:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
For i As Integer = CInt(start1.Value) To CInt(end1.Value)
' TT= temp threading
Control.CheckForIllegalCrossThreadCalls = False
Dim TT As New System.Threading.Thread(New ParameterizedThreadStart(AddressOf ScanPort))
TT.IsBackground = True
TT.Start(i)
Next
End Sub
Private Sub ScanPort(ByVal portToScan As Object)
Dim port As Integer = CType(portToScan, Integer)
Debug.Print("Scanning Port: " & port)
System.Threading.Thread.Sleep(1000)
End Sub