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 は、コード行 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
ありがとう