我在VB .NET下面的代碼示例2008等效代碼2005
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框架2.0的工作;我如何才能完成相同的VB .net 2005 ?, VB .net 2005不支持對應於代碼行num的語法。 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
謝謝
在原始代碼中,它會從「CheckPathFunction」方法獲取返回值嗎?只要方法在指定的超時時間內完成,它就會返回true,但它實際上並不會查看該方法是否找到該文件。 –
@SteveDog,如果在未達到超時時檢測到文件存在或沒有達到,則返回相應的值,如果在達到超時時無法確定文件是否存在返回false,則此函數用於檢查文件是否存在在網絡共享中 –