I have the following code sample in 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
Unfortunately I have to work with Vb .net 2005 and net framework 2.0; How can I accomplish the same for VB .net 2005?, VB .net 2005 does not support the syntax corresponding to the code line num. 3:
Function() CheckPathFunction(path)
Please note that the function to call requires a parameter and returns a value
I’ve tried using a delegate as indicated next but does not work
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
Thanks
Taking as base structure the code by @eol the final working code is: