Currently I useDynamicInvoke
which is very slow. Still using theDelegate
type how can I directly invoke the Delegate
without late-binding/theDynamicInvoke
?
Delegate _method;
_method.DynamicInvoke(_args);
Thanks.
Currently I useDynamicInvoke
which is very slow. Still using theDelegate
type how can I directly invoke the Delegate
without late-binding/theDynamicInvoke
?
Delegate _method;
_method.DynamicInvoke(_args);
Thanks.
Invoke
is faster, but it's a bit "hidden". From MSDN on Delegate class
The common language runtime provides an Invoke method for each delegate type, with the same signature as the delegate. You do not have to call this method explicitly from C#, Visual Basic, or Visual C++, because the compilers call it automatically. The Invoke method is useful in reflection when you want to find the signature of the delegate type.
What this means is that when you create a delegate type, the Invoke
member is added with the correct signature by the compiler. This allows calling without going through DynamicInvoke
In c#, you use this like:
_method(_args);
//or
_method(typedArg1, typedArg2, andSoOn);
calling it as you would a normal method. This actually calls Invoke
, which should be much faster for you.