[英]Is it possible to get the arguments from a sub or function in vb2005 as an array?
是否可以从vb2005中的子或函数获取参数作为数组?
你解决了吗? 我不太清楚您的意思,但是从您对OP的评论来看,您是否希望同步线程以进行线程安全的调用?
Private WithEvents theThread As New threadedClass
Private Delegate Sub threaded_method_delegate(ByVal sender As Object, ByVal var1 As Integer, ByVal var2 As String)
Sub threaded_method(ByVal sender As Object, ByVal var1 As Integer, ByVal var2 As String) Handles theThread.threaded_method
If Me.InvokeRequired Then
' invoke this method on the same thread as 'Me'
Dim d As New threaded_method_delegate(AddressOf threaded_method)
d.Invoke(sender, var1, var2)
Else
' this method is now running on the same thread
' do stuff here
End If
End Sub
您可以在VS 2010中进行此操作,但不能在2005中进行。这是通过DLR或动态语言运行时添加的功能。
使用反射:
Dim params() As System.Reflection.ParameterInfo = myObject.GetType().GetMethod("myObjectMethodName").GetParameters()
如果您可以控制成员签名,则可以将所有参数封装到一个类中,就像在常规.NET方式中在事件处理程序之间传递EventArgs
对象(或其子类)一样。
然后,只需将引用传递给封装类本身即可传递所有值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.