VB.net的Address Of 如何实现传参?
在写vb.net代码时,遇到个棘手的问题,如下:Public Class Form1
Public Delegate Sub FnVoid()
Public Shared Sub MytestFunc(欲传递参数)
Dim script As String
Dim fn As FnVoid
Dim ptr As IntPtr
fn = New FnVoid(AddressOf 我的函数) '这里如何实现传递上面的【欲传递参数】?或者其他方法,能实现目的也可以
End Sub
Public Shared Sub 我的函数()
MsgBox("传递的参数为:" & ???)
End Sub
查了下资料,有说使用线程的:
Public Shared Sub Main()
Dim thread As New Thread(AddressOf Foo)
thread.Start("hello")
thread.Join()
End Sub
Private Shared Sub Foo(ByVal value As Object)
MsgBox(value)
End Sub
但是Dim thread As New Thread(AddressOf Foo)之后,如何将thread传递给fn = New FnVoid(AddressOf 我的函数)?
尝试使用fn = New FnVoid(thread),失败。
感谢各位的帮助! VB平时不怎么用,大概这样?
Public Class Form1
Public Delegate Sub FnVoid(o As Object)
Public Shared Sub MytestFunc(欲传递参数 As Object)
Dim script As String
Dim fn As FnVoid
Dim ptr As IntPtr
fn = New FnVoid(AddressOf 我的函数)
fn.Invoke(欲传递参数)
End Sub
Public Shared Sub 我的函数(o As Object)
MsgBox("传递的参数为:" + o )
End Sub
End Class
页:
[1]