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:
- will
userlookup
disposed when linq enumerable disposed? - if how happen?
- 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
Post a Comment