c# - Are there any notable differences between calling an event handling using 'Invoke' and using a 'traditional method call'? -


an event handler can invoked either of following:

someeventhandler.invoke(this, new eventargs()); 

or

someeventhandler(this, new eventargs()); 

are there notable differences between 2 versions? perhaps in terms of performance?

they same. compiled same code. difference 2 invoke method allows (in c# 6) use null-conditional operator ?. check if handler initialized before invoke it. in first case, have following

if (someeventhandler != null)     someeventhandler(this, new eventars()); 

whereas invoke can

someeventhandler?.invoke(this, new eventargs()); 

i hope helps.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

Qt QGraphicsScene is not accessable from QGraphicsView (on Qt 5.6.1) -

What is happening when Matlab is starting a "parallel pool"? -