c# - Task.Factory.StartNew "action" argument and higher level local variables -


consider this:

void startupdate(datarequest datarequest) {     task.factory.startnew(request => {... "request" ...},          datarequest); } 

now, question: can use datarequest inside lambda expression, instead of passing second parameter startnew method? concern - method executed on different thread , i'm not sure if datarequest keep state when used there.

yes, can.
called closure; it's powerful feature.

the thread-safety, or lack thereof, no different.
whether instance through closure or through startnew parameter, it's still same object. (unless it's struct, indescribably evil)


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -