我在 VB .net 2008 中有以下代码示例
Public Function CheckPathFunction(ByVal path As String) As Boolean
Return System.IO.File.Exists(path)
End Function
Public Function PathExists(ByVal path As String, ByVal timeout As Integer) As Boolean
Dim exists As Boolean = True
Dim t As New Thread(DirectCast(Function() CheckPathFunction(path), ThreadStart))
t.Start()
Dim completed As Boolean = t.Join(timeout)
If Not completed Then
exists = False
t.Abort()
End If
Return exists
End Function
不幸的是,我必须使用 Vb .net 2005 和 net framework 2.0;我怎样才能为 VB .net 2005 完成相同的操作?,VB .net 2005 不支持与代码行编号对应的语法。3:
Function() CheckPathFunction(path)
请注意,要调用的函数需要一个参数并返回一个值
我已尝试使用如下所示的委托,但不起作用
Private Delegate Function CheckPath(ByVal path As String) As Boolean
Public Function CheckPathFunction(ByVal path As String) As Boolean
Return IO.File.Exists(path)
End Function
Public Function PathExists(ByVal path As String, ByVal timeout As Integer) As Boolean
Dim checkPathDelegate As New CheckPath(AddressOf CheckPathFunction)
Dim exists As Boolean = True
Dim t As New Thread(checkPathDelegate(path))
t.Start()
Dim completed As Boolean = t.Join(timeout)
If Not completed Then
exists = False
t.Abort()
End If
Return exists
End Function
谢谢