Question

This question may sound trivial, but let me ask it nevertheless.

I found on the Internet the following example of calling an anonymous method using Invoke in VB.NET:

Invoke(New MethodInvoker(Sub() SomeMethod(param1)))

But why not call it this way, which looks cleaner? Is there any difference?

Invoke(Sub() SomeMethod(param1))
Was it helpful?

Solution

Just to conclude and close the topic. Based on the comments, both the examples of Invoke calls are correct, but the one using MethodInvoker instantiation is faster, because no extra typecasting has to be performed at runtime, as MrPaulch stated.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top