c# - Disposing resource in Linq statement lambdas -


i have code:

 using(var userlookup = new userlookup()) {     = somecollection                      .select(t =>                       {                         var user = userlookup.userlookup(t.userid);                         return new wrapper                         {                            userstring = string.format("{0} {1} ({2})",                                            user.firstname, user.lastname, t.userid),                            someotherproperty = t.somefunction()                            etc..                         };                      }); } 

when something accessed objectdisposedexception. can solved removing using block. if this:

  1. will userlookup disposed when linq enumerable disposed?
  2. if how happen?
  3. is there way re-structure code dispose userlookup instance when enumerable disposed while still keeping deferred excecution?

(im sure call tolist() inside using block , work fine, , i'll that, curiosities sake)

i should mention something property on mvc view model.

is there way re-structure code dispose userlookup instance when enumerable disposed while still keeping deferred execution?

you'd need pass in userlookup instance method generating sequence, , dispose of after done processing results.

(im sure call tolist() inside using block , work fine, , i'll that, curiosities sake)

yes, cause enumerable executed before userlookup disposed, , avoid issue.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -