Any performance issues using CallByName?

  • Thread starter Thread starter Rob R. Ainscough
  • Start date Start date
R

Rob R. Ainscough

I use a generic Processing form (modal) where I pass it an object and method
name and parameters if needed and then use CallbyName to execute the passed
in method. What this does for me is lock out user input on the parent form
as the Processing form has no input controls until all processing is
complete.

I was curious if CallByName is a good way to perform this operation?
 
It would be better if all the objects passed in implemented the same
interface and the modal form called a known method. Any params can be
stored within the object instance ahead of time or passed as a generic
object array.

Another way to handle this is to use delegates.. pass a delegate to
the form allong with an object array of params, and the form can
invoke the delegate. This would work fine but in my opinion the
interface method is a cleaner implementation.

CallByName uses late binding and reflection internally and has a lot
of overhead that isn't necessary for the task.

HTH,

Sam
 
Unfortunately the purpose of the Processing form is to be generic in nature
so the methods and objects are not known ahead of time. The CallByName is
only used once (not used in a loop).

Do you have any specific numbers to indicate the overhead of CallByName vs.
another approach?

Thanks, Rob.
 
So what's wrong with using a Delegate? That's generic.

I don't think CallByName would be a performance problem in your case
since it's only called once for a large operation, but in my opinion
it's a bad function to use. I fall in "program the VB.NET without VB
camp". In general, when a OOP/.NET mechanism exists to accomplish the
same goal, I would opt for that alternative. Delegates would work
well for your situation.

Sam
 
Sam,

Hmmm...yes the Delegates approach may just work for me -- and appears it
might be about the same coding effort.

Thanks, Rob.
 
See MethodInfo Class and it's .Invoke member

Dim myType As Type = objClass.GetType()
Dim myMethod As MethodInfo = myType.GetMethod("strFnName")
myMethod.Invoke(objClass, Args)

where "strFnName" is your method name and "Args" is an array of parameter
values (objects) for the method's arguments in the same order.
 
Back
Top