c# - Inlining some events in BackgroundWorker? -


im not sure, called inlining when in 1 line?

i code have backgroundworker. doworker enforce sleep of on sec , runworkercompleted noe bit of code. possible instead of defining function in 1 line like

.dowork += ((sender, arg) => { ... });  

and

.runworkercompleted += ((sender, arg... 

what right syntax this, , called? nice keep things simple when have simple task @ hand :-)

you confusing inlining lambda expressions. inlining replacing calling of method body, example:

int timestwo(int x)  {    return x * 2; }  //before inlining: int = timestwo(6) + timestwo(7); //after inlining: int = 6 * 2 + 7 * 2; 

this compiler optimization technique avoid method call overhead.

for backgroundworker example correct syntax be:

 backgroundworker worker = new backgroundworker();  worker.dowork += (sender, e) => runmymethod();  //or  worker.dowork += (sender, e) => { runmymethod(); } 

for more information see msdn.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -